From: David Miller <davem@davemloft.net>
To: vapier@gentoo.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] netlink: drop (int) cast on length arg in NLMSG_OK
Date: Thu, 05 Mar 2015 21:43:28 -0500 (EST) [thread overview]
Message-ID: <20150305.214328.1364725716743583555.davem@davemloft.net> (raw)
In-Reply-To: <1425534428-24182-1-git-send-email-vapier@gentoo.org>
From: Mike Frysinger <vapier@gentoo.org>
Date: Thu, 5 Mar 2015 00:47:08 -0500
> The NLMSG_OK macro compares three things:
> - the len arg from the user
> - a size_t: sizeof(struct nlmsghdr)
> - an int: sizeof(struct nlmsghdr) casted
> - an u32: the nlmsghdr->nlmsg_len member
>
> When building with -Wsign-compare, this macro triggers a signed compare
> warning. This is because it compares len to an int, and then compares
> it to a u32. If len is signed, we get a warning due to the last test.
> If len is unsigned, we get a warning due to the first test. Like in
> strace:
> socketutils.c:145:8: warning: comparison between signed and unsigned
> integer expressions [-Wsign-compare]
>
> Lets drop the int cast on the first sizeof. This way, once the user
> casts len to an unsigned value, everything shakes out correctly.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
I don't think we can change this. If you get rid of the 'int' cast
then code is going to end up with a signed comparison for the first
test even if 'len' is signed, and that's a potential security issue.
prev parent reply other threads:[~2015-03-06 2:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-05 5:47 [PATCH] netlink: drop (int) cast on length arg in NLMSG_OK Mike Frysinger
2015-03-06 2:43 ` David Miller [this message]
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=20150305.214328.1364725716743583555.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=vapier@gentoo.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).