Skip to contentSkip to conversation

net: compat: fix msg_controllen overflow in scm_detach_fds_compat()

PATCH In review Young Xiao 2 participants 3 messages Jun 4, 2019

Subsystems (2)
lore
Share & tools
lore

Young Xiao

author
#0 lore raw

PATCH 1/1 net: compat: fix msg_controllen overflow in scm_detach_fds_compat()

There is a missing check between kmsg->msg_controllen and cmlen, which can possibly lead to overflow.

This bug is similar to vulnerability that was fixed in commit 6900317f5eff ("net, scm: fix PaX detected msg_controllen overflow in scm_detach_fds").

---
 net/compat.c | 2 ++
 1 file changed, 2 insertions(+)
net/compat.c +2 -0
index a031bd3..8e74dfb 100644
@@ -301,6 +301,8 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
 			err = put_user(cmlen, &cm->cmsg_len);
 		if (!err) {
 			cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
+			if (kmsg->msg_controllen < cmlen)
+				cmlen = kmsg->msg_controllen;
 			kmsg->msg_control += cmlen;
 			kmsg->msg_controllen -= cmlen;
 		}
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · Young Xiao

There is a missing check between kmsg->msg_controllen and cmlen, which can possibly lead to overflow.

This bug is similar to vulnerability that was fixed in commit 6900317f5eff ("net, scm: fix PaX detected msg_controllen overflow in scm_detach_fds").

Back then I mentioned in commit 6900317f5eff:

In case of MSG_CMSG_COMPAT (scm_detach_fds_compat()), I haven't seen an issue in my tests as alignment seems always on 4 byte boundary. Same should be in case of native 32 bit, where we end up with 4 byte boundaries as well.

Do you have an actual reproducer or is it based on code inspection?

Quoted 19 lines
---
 net/compat.c | 2 ++
 1 file changed, 2 insertions(+)
net/compat.c +2 -0
index a031bd3..8e74dfb 100644
@@ -301,6 +301,8 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
 			err = put_user(cmlen, &cm->cmsg_len);
 		if (!err) {
 			cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
+			if (kmsg->msg_controllen < cmlen)
+				cmlen = kmsg->msg_controllen;
 			kmsg->msg_control += cmlen;
 			kmsg->msg_controllen -= cmlen;
 		}
author
#2 lore raw
Quoted 8 lines · Daniel Borkmann
Quoted 5 lines · Young Xiao

There is a missing check between kmsg->msg_controllen and cmlen, which can possibly lead to overflow.

This bug is similar to vulnerability that was fixed in commit 6900317f5eff ("net, scm: fix PaX detected msg_controllen overflow in scm_detach_fds").

Quoted 8 lines

Back then I mentioned in commit 6900317f5eff:

In case of MSG_CMSG_COMPAT (scm_detach_fds_compat()), I haven't seen an issue in my tests as alignment seems always on 4 byte boundary. Same should be in case of native 32 bit, where we end up with 4 byte boundaries as well.

Do you have an actual reproducer or is it based on code inspection?

based on inspection.

Quoted 21 lines
Quoted 20 lines
---
 net/compat.c | 2 ++
 1 file changed, 2 insertions(+)
net/compat.c +2 -0
index a031bd3..8e74dfb 100644
@@ -301,6 +301,8 @@ void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
                      err = put_user(cmlen, &cm->cmsg_len);
              if (!err) {
                      cmlen = CMSG_COMPAT_SPACE(i * sizeof(int));
+                     if (kmsg->msg_controllen < cmlen)
+                             cmlen = kmsg->msg_controllen;
                      kmsg->msg_control += cmlen;
                      kmsg->msg_controllen -= cmlen;
              }
Signature · 4 lines
Best regards!

Young
-----------------------------------------------------------