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=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,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 EF352C47257 for ; Mon, 4 May 2020 20:32:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B1C9C205ED for ; Mon, 4 May 2020 20:32:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="a5TSD9pf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1C9C205ED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 473188E007F; Mon, 4 May 2020 16:32:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 423908E0058; Mon, 4 May 2020 16:32:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33A388E007F; Mon, 4 May 2020 16:32:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id 17EA68E0058 for ; Mon, 4 May 2020 16:32:11 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B1C1582499A8 for ; Mon, 4 May 2020 20:32:10 +0000 (UTC) X-FDA: 76780183620.03.heat95_300fff2456142 X-HE-Tag: heat95_300fff2456142 X-Filterd-Recvd-Size: 4431 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 May 2020 20:32:10 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id a31so505140pje.1 for ; Mon, 04 May 2020 13:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/vbL5b//yF/QRmFP+MoSE68BAHXcNHhnOpnaTu3IOJk=; b=a5TSD9pfl0Wo9vabYLrSXLxTVVKU66mKWR1tH0UvpYG1h/isiZjp2UEyo5ad63Um08 h7U/FeUjdcQju5xb2dOuvC2a9NIkOwmo/5mWo2S4cXMs8Ofsfh40SfMzVwiu2+czcE22 0qctPwe7ZHi0/GQOjEUxfg4fhXO1QPFCEBQUo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/vbL5b//yF/QRmFP+MoSE68BAHXcNHhnOpnaTu3IOJk=; b=fRaTBVnjsp+/0kVtLWjs9+kEJqntI0pL0qpde9n3VGaWSC0wGeG1OxtB21Z7emFkjZ HfliWpOGQS5KMdfMuMZY493b5j7YbTy06QltCFC5oS9JtZP7RJ9d7W+YRI82JMGz603g 78pXo7fssaB6hiTcNET0qi75OPk1GuvZkzbs6PTpuYFxUfyHuvqUcREfwHJwFDh5Th6a q+TSMSxdwOenvT3gYP+hGJn/H65RaCEdSmxiJaHr9Vugws0JEhzpJ8qM6w5MRjyDTb3t QYipJ/A+BlnxhA2pwUSXmuZaXzDjwbPaU8LLoYf9rlclH5bT5sPK28M6H6VsjtzQBdx1 PwUw== X-Gm-Message-State: AGi0PubFQNfxooi7wSCmzSAgvfvVxnOFMLU6SlIbBfSjxraPMTS9UAhU 1r71N/zxYJyX82ZjT6tfdlKmzQ== X-Google-Smtp-Source: APiQypJi2e/BGexLb329/SV08Hw+CjijJzLekv0lVmvaIk7rg1143PDSkgQrAePUi0XUCjRFMJ9ulQ== X-Received: by 2002:a17:902:261:: with SMTP id 88mr972081plc.308.1588624329164; Mon, 04 May 2020 13:32:09 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w75sm9506390pfc.156.2020.05.04.13.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2020 13:32:08 -0700 (PDT) Date: Mon, 4 May 2020 13:32:07 -0700 From: Kees Cook To: Luis Chamberlain Cc: Christoph Hellwig , Iurii Zaikin , Alexey Dobriyan , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] sysctl: Make sure proc handlers can't expose heap memory Message-ID: <202005041329.169799C65D@keescook> References: <202005041205.C7AF4AF@keescook> <20200504195937.GS11244@42.do-not-panic.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200504195937.GS11244@42.do-not-panic.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, May 04, 2020 at 07:59:37PM +0000, Luis Chamberlain wrote: > On Mon, May 04, 2020 at 12:08:55PM -0700, Kees Cook wrote: > > Just as a precaution, make sure that proc handlers don't accidentally > > grow "count" beyond the allocated kbuf size. > > > > Signed-off-by: Kees Cook > > --- > > This applies to hch's sysctl cleanup tree... > > --- > > fs/proc/proc_sysctl.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c > > index 15030784566c..535ab26473af 100644 > > --- a/fs/proc/proc_sysctl.c > > +++ b/fs/proc/proc_sysctl.c > > @@ -546,6 +546,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, > > struct inode *inode = file_inode(filp); > > struct ctl_table_header *head = grab_header(inode); > > struct ctl_table *table = PROC_I(inode)->sysctl_entry; > > + size_t count_max = count; > > void *kbuf; > > ssize_t error; > > > > @@ -590,6 +591,8 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf, > > > > if (!write) { > > error = -EFAULT; > > + if (WARN_ON(count > count_max)) > > + count = count_max; > > That crash a system with panic-on-warn. I don't think we want that? Eh? None of the handlers should be making this mistake currently and it's not a mistake that can be controlled from userspace. WARN() is absolutely what's wanted here: report an impossible situation (and handle it gracefully for the bulk of users that don't have panic_on_warn set). -- Kees Cook