lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 5 May 2020 13:41:44 -0700
From:   Kees Cook <keescook@...omium.org>
To:     Greg KH <gregkh@...uxfoundation.org>
Cc:     Luis Chamberlain <mcgrof@...nel.org>,
        Christoph Hellwig <hch@....de>,
        Iurii Zaikin <yzaikin@...gle.com>,
        Alexey Dobriyan <adobriyan@...il.com>, linux-mm@...ck.org,
        linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] sysctl: Make sure proc handlers can't expose heap memory

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 <keescook@...omium.org>
> > > > > ---
> > > > > 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ