Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1117194yba; Thu, 18 Apr 2019 15:42:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqylWhmErtTTJO2vISDuXihkZeA2FixLzKSPWMTwKaj65IMq8u76KCASqBXOFnb5ztX0/DZt X-Received: by 2002:aa7:8282:: with SMTP id s2mr196168pfm.7.1555627326737; Thu, 18 Apr 2019 15:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555627326; cv=none; d=google.com; s=arc-20160816; b=ApV2gOJKYlcXaL2+FWFy17+HyRXpoM78DxvdMvnrsOPBepotRlsL0tHCdbn1KLIO7U v6HHbshxYZQFk55JYX5Ey0spNdD5x2C9XQsciCFRTOYOE41ZG5X15TKcz9UsGbe/62Bw N54n0SwUlrEvfSUkFOcOq7lZdBToDD1wSLhD9e5O7byWrEeSQycsDvTSz1jHDdMU9TDm BjmSozbEmwTxDase4XtGsO+uov1xBWHEAELXD0YllB9ZMZSIEFc4XI4+ILKPfsEXbkW7 tj32FqrvjkbwGt3u2iJb3th+zyKMmygabvHjBLafyEQSlkis2JUssDw+55l6UACoze2V 5hbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=krWuM02sa8KwhfjtIBv79ql2H0++Xp9hPCN7FCvHhYw=; b=T8ZCaIqWFuVuel0ErANzBmZ7qoEn7n3D4s0mZWJTrFD9AzOZoVoK/lB2sic/1B6iuJ ztySXVrJuOK3+Cu7VfJUAUeZc2eKHhIX0nS+ryTcDIz6ZfpF9S0s5cZkhm1BZ/qNNiTm 35ga0XI4NwHSoCtjr5dk09P+WoC/FAgsIZaZD6Nuoz9ndJBMuR1FPDpMD5qbIUechJkB SbFTVMA7jsifKAKXNWps/svzMzdd6WwQEiJrPnuNvIgXGtUzVAXqZhgudZy/X12IzBWX 4GuZxJA96LVI/fy4WqgsLmKBHpfPdi8mIVu06hqgwPv7L6soxeBySZ6BoDlfjyZ26nbV FVcA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10si2987814pgq.293.2019.04.18.15.41.48; Thu, 18 Apr 2019 15:42:06 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726108AbfDRWks (ORCPT + 99 others); Thu, 18 Apr 2019 18:40:48 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33338 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbfDRWkr (ORCPT ); Thu, 18 Apr 2019 18:40:47 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E2FC519E1; Thu, 18 Apr 2019 22:40:46 +0000 (UTC) Date: Thu, 18 Apr 2019 15:40:45 -0700 From: Andrew Morton To: Matteo Croce Cc: LKML , linux-fsdevel@vger.kernel.org, Kees Cook Subject: Re: [PATCH v3] proc/sysctl: add shared variables for range check Message-Id: <20190418154045.2ad0bd50e73a6e71c0fac768@linux-foundation.org> In-Reply-To: <20190417131531.9525-1-mcroce@redhat.com> References: <20190417131531.9525-1-mcroce@redhat.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 17 Apr 2019 15:15:31 +0200 Matteo Croce wrote: > In the sysctl code the proc_dointvec_minmax() function is often used to > validate the user supplied value between an allowed range. This function > uses the extra1 and extra2 members from struct ctl_table as minimum and > maximum allowed value. > > On sysctl handler declaration, in every source file there are some readonly > variables containing just an integer which address is assigned to the > extra1 and extra2 members, so the sysctl range is enforced. > > The special values 0, 1 and INT_MAX are very often used as range boundary, > leading duplication of variables like zero=0, one=1, int_max=INT_MAX in > different source files: > > $ git grep -E '\.extra[12].*&(zero|one|int_max)\b' |wc -l > 245 > > This patch adds three const variables for the most commonly used values, > and use them instead of creating a local one for every object file. > > ... > > --- a/arch/s390/appldata/appldata_base.c > +++ b/arch/s390/appldata/appldata_base.c > @@ -220,15 +220,13 @@ appldata_timer_handler(struct ctl_table *ctl, int write, > void __user *buffer, size_t *lenp, loff_t *ppos) > { > int timer_active = appldata_timer_active; > - int zero = 0; > - int one = 1; > int rc; > struct ctl_table ctl_entry = { > .procname = ctl->procname, > .data = &timer_active, > .maxlen = sizeof(int), > - .extra1 = &zero, > - .extra2 = &one, > + .extra1 = (void *)&sysctl_zero, > + .extra2 = (void *)&sysctl_one, > }; Still not liking the casts :( Did we decide whether making extra1&2 const void*'s was feasible? I'm wondering if it would be better to do extern const int sysctl_zero; /* comment goes here */ #define SYSCTL_ZERO ((void *)&sysctl_zero) and then use SYSCTL_ZERO everywhere. That centralizes the ugliness and makes it easier to switch over if/when extra1&2 are constified. But it's all a bit sad and lame :(