Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp11182613imu; Thu, 6 Dec 2018 12:59:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/WDNjbi4j+46O7WUIYBw4eAbf4c5VnUiUR5jKfZU3Tr0f0058HO1ITA4L9Agf0alt8JOb1F X-Received: by 2002:a63:9c1a:: with SMTP id f26mr6927920pge.381.1544129943830; Thu, 06 Dec 2018 12:59:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544129943; cv=none; d=google.com; s=arc-20160816; b=ksjTZg3cTceMkJoDFPTxtdGmD2LVASk8/vsXHDTrRgpMAi6709KXDavUky41XyEOWV 9bCKP8n1h9ZanBV6OrAHpxzACIanIUZuPqhVH8yhVXMqt/qHHYDFCRZ/WRjVPHL9eEAh gLS1I/Ub2oYLKMDj4FWHaMmd31lnd0M/UV0kXV/+5xSny56sQ+eTuwvig4mIcBX7c5sM +zZtagc9cPYNgjsDbQ0pbLuBt/5tCA4a96nTzZdVcR4d7radni8Ep28diXbDrKQoZY9P WP0uk+pBHI8AOk3LBpmwZrm5BpkSiy2dScIfJcol11Hp8bz9TU6wVck6c26eOUMo270n DzuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uKVZaCD9ZtZ0SJxFxgVDNC1lXzqQAhGwc41Mmvh5cwQ=; b=SZzBkF/gxXs/llHWQL9bS2790oJY00gCeB/9NBRtDq38yZuWDt0xl1TaIALd2jHSgy Q+9w3+8bRHhzzzLPsXSrUeTWVDfGUuBTAmG5Z2bEWhim7TY92MH+bOsABvvuUFooOrCe SdobkDkBO/W9nzKlAD+mxHeRHX57u01nrnpiIrtHzy4C0cHL3ffAwFqsero5jIuVTtiQ lgtYkK0/NEBhMakznsUygJl8XZPIUegZLHhB63yjtMzTnuLwZotiEjKjpXoxRqC1bk22 hr9Rhaj1QEcCiUm5ItdSf+IqJpfASA44rJvYjIA8T9E1OlzpGwDrQg+CkASww8ZaQA+i QI9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FYfsDMQq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l24si1032768pgj.171.2018.12.06.12.58.48; Thu, 06 Dec 2018 12:59:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FYfsDMQq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725976AbeLFU6A (ORCPT + 99 others); Thu, 6 Dec 2018 15:58:00 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:41469 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbeLFU57 (ORCPT ); Thu, 6 Dec 2018 15:57:59 -0500 Received: by mail-yb1-f195.google.com with SMTP id n134so1420346ybf.8 for ; Thu, 06 Dec 2018 12:57:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uKVZaCD9ZtZ0SJxFxgVDNC1lXzqQAhGwc41Mmvh5cwQ=; b=FYfsDMQqy0Teb7YhaLy8vQ5hd8iM+SBZt7LcK0chS2e7o4sZd323pLhYF1BK+OH5Rh mB3Xv1TMY2NpEJUNAL4CXO9ajl2spep7AnyMbUKFqIm0lNKklKU/cMVU7FttQzF0zxnI AOjd2Dryd1Xvordm+7ysqJIa322ZSWULVmC0M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uKVZaCD9ZtZ0SJxFxgVDNC1lXzqQAhGwc41Mmvh5cwQ=; b=YMDqN+D2lwXoDy+x1L9tGOGZ2ddhtc2yZQCV/L0hO1SvZkR32WiGfSzpsFwjqJh4Ms Efwx5Qxx0Ue+rqva73gnq4dDS6KThs6s5Ejoi0jRTJ2IwWELDXPtwyhR0dQfrFhhTeIC gTG5bNWSR4r4lGCRjXi9MJAQaTbma7FP51D8CpVFwpf1EsS/P1C2AgAyv07wzQZixqOz vpTx8rFiWRfP7Q1eYUhATONPTaqDrB7qkJ4hzh+zR/2McuVeFH3rg1tqAEvQUnYqV1Ep hneo0y8t+cl5Yotgdu3D2TWYJ7v/bJRFaEX5lAN7mm4jZkKBGm0rbLAPt/hDarOMlyrx wmYg== X-Gm-Message-State: AA+aEWZ21mo510nvRE+45VJFURkN3J9wt/Njcb9HU3DfmlVebNAX5bhe Y6LId0n4/cqb3l4PPIYM2WBubpp1MDs= X-Received: by 2002:a25:5e43:: with SMTP id s64mr18773492ybb.242.1544129877333; Thu, 06 Dec 2018 12:57:57 -0800 (PST) Received: from mail-yw1-f48.google.com (mail-yw1-f48.google.com. [209.85.161.48]) by smtp.gmail.com with ESMTPSA id i13sm357479ywe.53.2018.12.06.12.57.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 12:57:55 -0800 (PST) Received: by mail-yw1-f48.google.com with SMTP id j6so164487ywj.6 for ; Thu, 06 Dec 2018 12:57:55 -0800 (PST) X-Received: by 2002:a81:28c7:: with SMTP id o190mr30827025ywo.288.1544129874790; Thu, 06 Dec 2018 12:57:54 -0800 (PST) MIME-Version: 1.0 References: <1544081775-15720-1-git-send-email-cheng.lin130@zte.com.cn> <20181206085242.GG28501@garbanzo.do-not-panic.com> In-Reply-To: <20181206085242.GG28501@garbanzo.do-not-panic.com> From: Kees Cook Date: Thu, 6 Dec 2018 12:57:43 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] proc/sysctl: fix return error for proc_doulongvec_minmax To: "Luis R. Rodriguez" Cc: cheng.lin130@zte.com.cn, Andrew Morton , LKML , "linux-fsdevel@vger.kernel.org" , zhong.weidong@zte.com.cn, wang.yi59@zte.com.cn, Alexander.Levin@microsoft.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 6, 2018 at 12:52 AM Luis Chamberlain wrote: > > On Thu, Dec 06, 2018 at 03:36:15PM +0800, Cheng Lin wrote: > > If the number of input parameters is less than the total > > parameters, an EINVAL error will be returned. > > > > e.g. > > We use proc_doulongvec_minmax to pass up to two parameters > > with kern_table. > > > > { > > .procname = "monitor_signals", > > .data = &monitor_sigs, > > .maxlen = 2*sizeof(unsigned long), > > .mode = 0644, > > .proc_handler = proc_doulongvec_minmax, > > }, > > > > Reproduce: > > When passing two parameters, it's work normal. But passing > > only one parameter, an error "Invalid argument"(EINVAL) is > > returned. > > > > [root@cl150 ~]# echo 1 2 > /proc/sys/kernel/monitor_signals > > [root@cl150 ~]# cat /proc/sys/kernel/monitor_signals > > 1 2 > > [root@cl150 ~]# echo 3 > /proc/sys/kernel/monitor_signals > > -bash: echo: write error: Invalid argument > > [root@cl150 ~]# echo $? > > 1 > > [root@cl150 ~]# cat /proc/sys/kernel/monitor_signals > > 3 2 > > [root@cl150 ~]# > > > > The following is the result after apply this patch. No error > > is returned when the number of input parameters is less than > > the total parameters. > > > > [root@cl150 ~]# echo 1 2 > /proc/sys/kernel/monitor_signals > > [root@cl150 ~]# cat /proc/sys/kernel/monitor_signals > > 1 2 > > [root@cl150 ~]# echo 3 > /proc/sys/kernel/monitor_signals > > [root@cl150 ~]# echo $? > > 0 > > [root@cl150 ~]# cat /proc/sys/kernel/monitor_signals > > 3 2 > > [root@cl150 ~]# > > > > There are three processing functions dealing with digital parameters, > > __do_proc_dointvec/__do_proc_douintvec/__do_proc_doulongvec_minmax. > > > > This patch deals with __do_proc_doulongvec_minmax, just as > > __do_proc_dointvec does, adding a check for parameters 'left'. In > > __do_proc_douintvec, its code implementation explicitly does not > > support multiple inputs. > > > > static int __do_proc_douintvec(...){ > > ... > > /* > > * Arrays are not supported, keep this simple. *Do not* add > > * support for them. > > */ > > if (vleft != 1) { > > *lenp = 0; > > return -EINVAL; > > } > > ... > > } > > > > So, just __do_proc_doulongvec_minmax has the problem. And most use of > > proc_doulongvec_minmax/proc_doulongvec_ms_jiffies_minmax just have one > > parameter. > > > > Signed-off-by: Cheng Lin > > Thanks for fixing up the commit log. > > Acked-by: Luis Chamberlain Reviewed-by: Kees Cook -Kees > > I think we can live with this outside of stable. So stable is not > needed. But I would not be surprised if autosel algorithm will end > up picking it up. And if so.. well, it cannot hurt. > > Luis -- Kees Cook