Re: [PATCH v2 1/5] fcntl: Cast commands with int args explicitly

From: Al Viro
Date: Fri Apr 14 2023 - 11:46:44 EST


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.