mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Fix memory overwriting issue when copy an address to user space
@ 2020-07-20  4:34 lebon zhou
  2020-07-20 15:12 ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: lebon zhou @ 2020-07-20  4:34 UTC (permalink / raw)
  To: davem, kuba; +Cc: linux-kernel, netdev

When application provided buffer size less than sockaddr_storage, then
kernel will overwrite some memory area which may cause memory corruption,
e.g.: in recvmsg case, let msg_name=malloc(8) and msg_namelen=8, then
usually application can call recvmsg successful but actually application
memory get corrupted.

Fix to return EINVAL when application buffer size less than
sockaddr_storage.

Signed-off-by: lebon.zhou <lebon.zhou@gmail.com>
---
 net/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/socket.c b/net/socket.c
index 976426d03f09..dc32b1b899df 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -229,7 +229,7 @@ static int move_addr_to_user(struct
sockaddr_storage *kaddr, int klen,
         return err;
     if (len > klen)
         len = klen;
-    if (len < 0)
+    if (len < 0 || len < klen)
         return -EINVAL;
     if (len) {
         if (audit_sockaddr(klen, kaddr))
--
2.22.0

^ permalink raw reply	[flat|nested] 6+ messages in thread
* [PATCH] Fix memory overwriting issue when copy an address to user space
@ 2020-07-17 10:31 lebon zhou
  2020-07-17 17:50 ` Jakub Kicinski
  2020-07-18  1:43 ` David Miller
  0 siblings, 2 replies; 6+ messages in thread
From: lebon zhou @ 2020-07-17 10:31 UTC (permalink / raw)
  To: davem, kuba; +Cc: linux-kernel

When application provided buffer size less than sockaddr_storage, then
kernel will overwrite some memory area which may cause memory corruption,
e.g.: in recvmsg case, let msg_name=malloc(8) and msg_namelen=8, then
usually application can call recvmsg successful but actually application
memory get corrupted.

Fix to return EINVAL when application buffer size less than
sockaddr_storage.

Signed-off-by: lebon.zhou <lebon.zhou@gmail.com>
---
 net/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/socket.c b/net/socket.c
index 976426d03f09..dc32b1b899df 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -229,7 +229,7 @@ static int move_addr_to_user(struct
sockaddr_storage *kaddr, int klen,
         return err;
     if (len > klen)
         len = klen;
-    if (len < 0)
+    if (len < 0 || len < klen)
         return -EINVAL;
     if (len) {
         if (audit_sockaddr(klen, kaddr))
-- 
2.22.0

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

end of thread, other threads:[~2020-07-21  3:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20  4:34 [PATCH] Fix memory overwriting issue when copy an address to user space lebon zhou
2020-07-20 15:12 ` David Laight
2020-07-21  4:23   ` lebon zhou
  -- strict thread matches above, loose matches on Subject: below --
2020-07-17 10:31 lebon zhou
2020-07-17 17:50 ` Jakub Kicinski
2020-07-18  1:43 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®