netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: netlink: prevent potential integer overflow in nlmsg_new()
@ 2025-01-22 13:49 Dan Carpenter
  2025-01-22 13:52 ` Przemek Kitszel
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Dan Carpenter @ 2025-01-22 13:49 UTC (permalink / raw)
  To: Thomas Graf
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, netdev, linux-kernel, kernel-janitors

The "payload" variable is type size_t, however the nlmsg_total_size()
function will a few bytes to it and then truncate the result to type
int.  That means that if "payload" is more than UINT_MAX the alloc_skb()
function might allocate a buffer which is smaller than intended.

Cc: stable@vger.kernel.org
Fixes: bfa83a9e03cf ("[NETLINK]: Type-safe netlink messages/attributes interface")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 include/net/netlink.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/net/netlink.h b/include/net/netlink.h
index e015ffbed819..ca7a8152e6d4 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -1015,6 +1015,8 @@ static inline struct nlmsghdr *nlmsg_put_answer(struct sk_buff *skb,
  */
 static inline struct sk_buff *nlmsg_new(size_t payload, gfp_t flags)
 {
+	if (payload > INT_MAX)
+		return NULL;
 	return alloc_skb(nlmsg_total_size(payload), flags);
 }
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-01-24 16:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-22 13:49 [PATCH net] net: netlink: prevent potential integer overflow in nlmsg_new() Dan Carpenter
2025-01-22 13:52 ` Przemek Kitszel
2025-01-23  5:48   ` Dan Carpenter
2025-01-22 14:24 ` Jakub Kicinski
2025-01-24 14:35   ` Dan Carpenter
2025-01-24 16:02     ` Jakub Kicinski
2025-01-22 15:51 ` Simon Horman

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).