From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF5CCC43219 for ; Tue, 30 Apr 2019 18:14:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8FA3920854 for ; Tue, 30 Apr 2019 18:14:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WPBSwm2V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726102AbfD3SOg (ORCPT ); Tue, 30 Apr 2019 14:14:36 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:39504 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfD3SOf (ORCPT ); Tue, 30 Apr 2019 14:14:35 -0400 Received: by mail-yw1-f68.google.com with SMTP id x204so634739ywg.6 for ; Tue, 30 Apr 2019 11:14:35 -0700 (PDT) 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=Bse4S0Z7lUf/SmcUVMhmxnkZgM+H7sFlIuWL16fY2hs=; b=WPBSwm2V0oeuI+bplyqdGWE4RLVzulE0noF0etJZsE7TZccsrAjKH1+fPUa8IBFj1/ 3RZeVujhrkl2FmoxDwgroiXOjcRApCnE+Uuqqt7EOlLxPbIkJOWvOF8rWeR6XIPlKW9g eckn6b7lehgVJ0wG5jRpqcZ8GWsxzBmROvb8E= 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=Bse4S0Z7lUf/SmcUVMhmxnkZgM+H7sFlIuWL16fY2hs=; b=Lar0XRHJo89lzAeNwhYJ2OIPolWbXNT6HGzaHL7hcG+20cRIaJ4MX0m/8AU24bMPaG l6Ox0tO7ntjGlh3NsJyjicrqGEoBkcu7S/9ePxMnYYK8oS+wtZqD/stUFM5JfXLCrzkQ SzEpdH9uKiEL467MW4UyJwtB+pvYU0Z1lJBxvEIBxXLMdyz5QAyOK77i16sAaXfstOx2 F/uoeXh0QeaAyM18B6+NAqNuYZv1Ya49EaeUDC0abpcMN6BMSQGe6DgQ8GseOiJyXO32 YJJl6n/DhAPyusPUYaYusTJf/a27Zy2It9MGMN0lTBp3xjGFB/wyT8aLEa7oISODpv3E u76w== X-Gm-Message-State: APjAAAUg6R+RD4DwuVaP3Edz1EnwKIoZb/wG7LiulazB+kKgNeOJW9mh au8S1NYehduF75r2T1eyHi2VLAebmXk= X-Google-Smtp-Source: APXvYqxu+IToeEAj6QXd1qWMVpxlzICRPVCBKllPUr0lc9IEXWIXuSXV4xKAjpA0aSGLWVTLKcer8A== X-Received: by 2002:a81:8448:: with SMTP id u69mr46987900ywf.295.1556648074590; Tue, 30 Apr 2019 11:14:34 -0700 (PDT) Received: from mail-yw1-f43.google.com (mail-yw1-f43.google.com. [209.85.161.43]) by smtp.gmail.com with ESMTPSA id z123sm3176988ywz.82.2019.04.30.11.14.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Apr 2019 11:14:33 -0700 (PDT) Received: by mail-yw1-f43.google.com with SMTP id t79so6608659ywc.7 for ; Tue, 30 Apr 2019 11:14:33 -0700 (PDT) X-Received: by 2002:a81:2e08:: with SMTP id u8mr52020872ywu.55.1556648072989; Tue, 30 Apr 2019 11:14:32 -0700 (PDT) MIME-Version: 1.0 References: <20190430180111.10688-1-mcroce@redhat.com> In-Reply-To: <20190430180111.10688-1-mcroce@redhat.com> From: Kees Cook Date: Tue, 30 Apr 2019 11:14:20 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5] proc/sysctl: add shared variables for range check To: Matteo Croce Cc: LKML , "linux-fsdevel@vger.kernel.org" , Andrew Morton , Matthew Wilcox Content-Type: text/plain; charset="UTF-8" Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Tue, Apr 30, 2019 at 11:01 AM 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 > 248 > > Add a const int array containing the most commonly used values, > some macros to refer more easily to the correct array member, > and use them instead of creating a local one for every object file. > > This is the bloat-o-meter output comparing the old and new binary > compiled with the default Fedora config: > > # scripts/bloat-o-meter -d vmlinux.o.old vmlinux.o > add/remove: 2/2 grow/shrink: 0/2 up/down: 24/-188 (-164) > Data old new delta > sysctl_vals - 12 +12 > __kstrtab_sysctl_vals - 12 +12 > max 14 10 -4 > int_max 16 - -16 > one 68 - -68 > zero 128 28 -100 > Total: Before=20583249, After=20583085, chg -0.00% > > Signed-off-by: Matteo Croce Acked-by: Kees Cook -- Kees Cook