Re: [PATCH] netlink: drop (int) cast on length arg in NLMSG_OK

2015-03-05 Thread David Miller
From: Mike Frysinger 
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 

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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] netlink: drop (int) cast on length arg in NLMSG_OK

2015-03-05 Thread David Miller
From: Mike Frysinger vap...@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 vap...@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.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] netlink: drop (int) cast on length arg in NLMSG_OK

2015-03-04 Thread Mike Frysinger
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 
---
 include/uapi/linux/netlink.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h
index 1a85940..3eb4e24 100644
--- a/include/uapi/linux/netlink.h
+++ b/include/uapi/linux/netlink.h
@@ -84,7 +84,7 @@ struct nlmsghdr {
 #define NLMSG_DATA(nlh)  ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
 #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
  (struct nlmsghdr*)(((char*)(nlh)) + 
NLMSG_ALIGN((nlh)->nlmsg_len)))
-#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
+#define NLMSG_OK(nlh,len) ((len) >= sizeof(struct nlmsghdr) && \
   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
   (nlh)->nlmsg_len <= (len))
 #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
-- 
2.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] netlink: drop (int) cast on length arg in NLMSG_OK

2015-03-04 Thread Mike Frysinger
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 vap...@gentoo.org
---
 include/uapi/linux/netlink.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/netlink.h b/include/uapi/linux/netlink.h
index 1a85940..3eb4e24 100644
--- a/include/uapi/linux/netlink.h
+++ b/include/uapi/linux/netlink.h
@@ -84,7 +84,7 @@ struct nlmsghdr {
 #define NLMSG_DATA(nlh)  ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
 #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)-nlmsg_len), \
  (struct nlmsghdr*)(((char*)(nlh)) + 
NLMSG_ALIGN((nlh)-nlmsg_len)))
-#define NLMSG_OK(nlh,len) ((len) = (int)sizeof(struct nlmsghdr)  \
+#define NLMSG_OK(nlh,len) ((len) = sizeof(struct nlmsghdr)  \
   (nlh)-nlmsg_len = sizeof(struct nlmsghdr)  \
   (nlh)-nlmsg_len = (len))
 #define NLMSG_PAYLOAD(nlh,len) ((nlh)-nlmsg_len - NLMSG_SPACE((len)))
-- 
2.3.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/