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.8 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,URIBL_BLOCKED autolearn=unavailable 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 D99E4C47254 for ; Tue, 5 May 2020 20:41:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9F07720752 for ; Tue, 5 May 2020 20:41:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XU6X9GMe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F07720752 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 2CF4D8E0006; Tue, 5 May 2020 16:41:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27F7A8E0003; Tue, 5 May 2020 16:41:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 194D78E0006; Tue, 5 May 2020 16:41:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id 019F18E0003 for ; Tue, 5 May 2020 16:41:47 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B8465180AD806 for ; Tue, 5 May 2020 20:41:47 +0000 (UTC) X-FDA: 76783836654.26.skate82_2cbbf37ca5f07 X-HE-Tag: skate82_2cbbf37ca5f07 X-Filterd-Recvd-Size: 5826 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 5 May 2020 20:41:47 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id 207so55238pgc.6 for ; Tue, 05 May 2020 13:41:47 -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=TBeTodJwY1sbypPr0O4/M7Oc5AId4qrDzBRpp3D+bWw=; b=XU6X9GMe8j4wKq96hvrcdX1ByQHmmyBW7U6O/ETyAHaaOeuNGkQLdp5aHsi+ZYAg/n ToTVv9P6DfvsQWmACbq/7EkvxkgQBisVFC+Cuteh8eSBPa0l95XCST9S/53ATidKpelR BE5pJ6fNUlqYODQ8vfoK3eOaI1hndoAxJQXJc= 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=TBeTodJwY1sbypPr0O4/M7Oc5AId4qrDzBRpp3D+bWw=; b=Y60CvcaihzdaHUg8IokcDTYNBOsPF/wstNblUbnZTL+qHFLvG64LYp9Z9vVcJ5dHF6 NDOYgLftLaxRCSYHtJyQr3p+dLxmUWZMucmEK7a7GJ8QOS1AgQ6zdd4UJkluZreKvQfV sMbb5RE5HdwN9FbFsnOHtLmcWD1nB0/YuudNpMqum34wmW/RT2yauOCVmN6ubnYFaJdF F1zy4xqf3ZvEU/og2fxinI4s/ULQXomkQizMPt+MuStgL9QnlPKGnll2I6puheI1wMpl 0Ww/+GDy4ziwrC98yTQqgUQ05QQweoM8FPt7mckEd9qhd5samsDetJKfssyISdGqXLn+ LhZQ== X-Gm-Message-State: AGi0PubcYbMV9rnRtxt/lmyejh6dBMYRXe2fQeQX2AkXHbdLGvy6M1QJ GG/8sBlRBkWPgUGh3+vUmv1sfw== X-Google-Smtp-Source: APiQypKneSUsTTVo+yZKgZiaXfs8Cdo88B6bTaJHGjy6DGrc5Y7iwWPQe9ZysHr3aN4qrrZAuhv8sQ== X-Received: by 2002:a62:d005:: with SMTP id p5mr5183995pfg.156.1588711306249; Tue, 05 May 2020 13:41:46 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g16sm2726879pfq.203.2020.05.05.13.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2020 13:41:45 -0700 (PDT) Date: Tue, 5 May 2020 13:41:44 -0700 From: Kees Cook To: Greg KH Cc: Luis Chamberlain , 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: <202005051339.5F1979C4DF@keescook> References: <202005041205.C7AF4AF@keescook> <20200504195937.GS11244@42.do-not-panic.com> <202005041329.169799C65D@keescook> <20200504215903.GT11244@42.do-not-panic.com> <20200505063441.GA3877399@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200505063441.GA3877399@kroah.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 Tue, May 05, 2020 at 08:34:41AM +0200, Greg KH wrote: > On Mon, May 04, 2020 at 09:59:03PM +0000, Luis Chamberlain wrote: > > On Mon, May 04, 2020 at 01:32:07PM -0700, Kees Cook wrote: > > > 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 would 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). > > > > Alrighty, Greg are you OK with this type of WARN_ON()? You recently > > expressed concerns over its use due to panic-on-warn on another patch. > > We should never call WARN() on any path that a user can trigger. > > If it is just a "the developer called this api in a foolish way" then we > could use a WARN_ON() to have them realize their mistake, but in my > personal experience, foolish developers don't even notice that kind of > mistake :( Right -- while it'd be nice if the developer noticed it, it is _usually_ an unsuspecting end user (or fuzzer), in which case we absolutely want a WARN (and not a BUG![1]) and have the situations handled gracefully, so it can be reported and fixed. -Kees [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#bug-and-bug-on -- Kees Cook