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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 17 Apr 2023 10:38:22 +0100
From:   Mark Rutland <mark.rutland@....com>
To:     Al Viro <viro@...iv.linux.org.uk>
Cc:     Luca Vizzarro <Luca.Vizzarro@....com>,
        linux-kernel@...r.kernel.org,
        Christian Brauner <brauner@...nel.org>,
        Jeff Layton <jlayton@...nel.org>,
        Chuck Lever <chuck.lever@...cle.com>,
        Kevin Brodsky <Kevin.Brodsky@....com>,
        Vincenzo Frascino <Vincenzo.Frascino@....com>,
        Szabolcs Nagy <Szabolcs.Nagy@....com>,
        Theodore Ts'o <tytso@....edu>,
        David Laight <David.Laight@...lab.com>,
        linux-fsdevel@...r.kernel.org, linux-morello@...lists.linaro.org
Subject: Re: [PATCH v2 1/5] fcntl: Cast commands with int args explicitly

On Fri, Apr 14, 2023 at 04:46:31PM +0100, Al Viro wrote:
> On Fri, Apr 14, 2023 at 04:24:55PM +0100, Luca Vizzarro wrote:
> >  	void __user *argp = (void __user *)arg;
> > +	int argi = (int)arg;
> 
> Strictly speaking, conversion from unsigned long to int is
> an undefined behaviour, unless the value fits into the
> range representable by int ;-)
> 
> >  	case F_SETFD:
> >  		err = 0;
> > -		set_close_on_exec(fd, arg & FD_CLOEXEC);
> > +		set_close_on_exec(fd, argi & FD_CLOEXEC);
> 
> Why?
> 
> >  	case F_SETSIG:
> >  		/* arg == 0 restores default behaviour. */
> > -		if (!valid_signal(arg)) {
> > +		if (!valid_signal(argi)) {
> 
> Why???
> 
> >  			break;
> >  		}
> >  		err = 0;
> > -		filp->f_owner.signum = arg;
> > +		filp->f_owner.signum = argi;
> >  		break;
> 
> These two are clearly bogus and I'd like to see more details
> on the series rationale, please.

I agree the first isn't necessary, but I don't think the second is bogus, since
valid_signal() takes an unsigned long and the man page for F_SETSIG says that
the argument is an int:

  https://man7.org/linux/man-pages/man2/fcntl.2.html

... though arguably that could be a bug in the man page.

The cover letter really should have quoted the description that Szabolcs wote
at:

  https://lore.kernel.org/linux-api/Y1%2FDS6uoWP7OSkmd@arm.com/

The gist being that where the calling convention leaves narrowing to callees
(as is the case on arm64 with our "AAPCS64" calling convention), if the caller
passes a type which is narrower than a register, the upper bits of that
register may contain junk.

So e.g. for F_SETSIG, if the userspace will try to pass some 32-bit value,
leaving bits 63:32 of the argument register containing arbitrary junk. Then
here we interprert the value as an unsigned long, considering that junk as part
of the argument. Then valid_signal(arg) may end up rejecting the argument due
to the junk uper bits, which is surprising to the caller as from its PoV it
passed a 32-bit value in the correct way.

So either:

* That's a documentation bug, and userspce needs to treat the agument to
  F_SETSIG as an unsigned long.

* The kernel needs to narrow the argument to an int (if required by the calling
  convention) to prevent that.

Does that make sense, or have I missed the point you were making?

Thanks,
Mark.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ