All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: linux-kernel@vger.kernel.org, Jeff Dike <jdike@addtoit.com>,
	Richard Weinberger <richard@nod.at>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	user-mode-linux-devel@lists.sourceforge.net
Subject: Re: [PATCH] um: Fix pointer cast
Date: Tue, 22 Dec 2015 22:30:16 +0000	[thread overview]
Message-ID: <20151222223016.GC20997@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1450817041-21236-1-git-send-email-mic@digikod.net>

On Tue, Dec 22, 2015 at 09:44:01PM +0100, Mickaël Salaün wrote:
> Fix a pointer cast typo introduced in v4.4-rc5 especially visible for
> the i386 subarchitecture where it results in a kernel crash.

Why the hell bother casting it at all?  _Any_ pointer will quietly convert
to void *, no typecasts needed.  The second argument of copy_from_user
is const void __user *; sc is struct sigcontext __user *sc, so
&sb->oldmask is either __u32 __user * or __u64 __user *, for 32bit and
64bit builds resp.  Either is assignment-compatible with
const void __user *.

Basically, cast is telling the typechecking logics "sod off, I know better".
And here it's not needed at all.  Moreover, the bug you are fixing here is
precisely that this code did *not* know better - if not for that cast,
compiler would've immediately pointed to the problem.

> -	if (copy_from_user(&set.sig[0], (void *)sc->oldmask, sizeof(set.sig[0])) ||
> +	if (copy_from_user(&set.sig[0], (void *)&sc->oldmask, sizeof(set.sig[0])) ||

Please, remove the cast completely.  Simply pass it &sc->oldmask and be
done with that.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


WARNING: multiple messages have this Message-ID (diff)
From: Al Viro <viro@ZenIV.linux.org.uk>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: linux-kernel@vger.kernel.org, Jeff Dike <jdike@addtoit.com>,
	Richard Weinberger <richard@nod.at>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	user-mode-linux-devel@lists.sourceforge.net
Subject: Re: [PATCH] um: Fix pointer cast
Date: Tue, 22 Dec 2015 22:30:16 +0000	[thread overview]
Message-ID: <20151222223016.GC20997@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1450817041-21236-1-git-send-email-mic@digikod.net>

On Tue, Dec 22, 2015 at 09:44:01PM +0100, Mickaël Salaün wrote:
> Fix a pointer cast typo introduced in v4.4-rc5 especially visible for
> the i386 subarchitecture where it results in a kernel crash.

Why the hell bother casting it at all?  _Any_ pointer will quietly convert
to void *, no typecasts needed.  The second argument of copy_from_user
is const void __user *; sc is struct sigcontext __user *sc, so
&sb->oldmask is either __u32 __user * or __u64 __user *, for 32bit and
64bit builds resp.  Either is assignment-compatible with
const void __user *.

Basically, cast is telling the typechecking logics "sod off, I know better".
And here it's not needed at all.  Moreover, the bug you are fixing here is
precisely that this code did *not* know better - if not for that cast,
compiler would've immediately pointed to the problem.

> -	if (copy_from_user(&set.sig[0], (void *)sc->oldmask, sizeof(set.sig[0])) ||
> +	if (copy_from_user(&set.sig[0], (void *)&sc->oldmask, sizeof(set.sig[0])) ||

Please, remove the cast completely.  Simply pass it &sc->oldmask and be
done with that.

  parent reply	other threads:[~2015-12-22 22:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-22 20:44 [PATCH] um: Fix pointer cast Mickaël Salaün
2015-12-22 20:44 ` Mickaël Salaün
2015-12-22 21:23 ` Richard Weinberger
2015-12-22 21:23   ` Richard Weinberger
2015-12-22 22:30 ` Al Viro [this message]
2015-12-22 22:30   ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151222223016.GC20997@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=jdike@addtoit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mic@digikod.net \
    --cc=richard@nod.at \
    --cc=torvalds@linux-foundation.org \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.