Thread (5 messages) flat view 5 messages, 4 authors, 2017-03-10

Re: [PATCH v2] selinux: check for address length in selinux_socket_bind()

From: Eric Dumazet <hidden>
Date: 2017-03-06 20:27:50
Also in: lkml, selinux

On Mon, 2017-03-06 at 19:46 +0100, Alexander Potapenko wrote:
KMSAN (KernelMemorySanitizer, a new error detection tool) reports use of
uninitialized memory in selinux_socket_bind():
...
quoted hunk ↗ jump to hunk
Signed-off-by: Alexander Potapenko <glider@google.com>
---
Changes since v1:
 - fixed patch description
 - fixed addrlen tests to match those in inet_bind() and inet6_bind()
   (per comment from Eric Dumazet)
---
 security/selinux/hooks.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 0a4b4b040e0a..ddc4aca6c840 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -4351,10 +4351,19 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
 		u32 sid, node_perm;
 
 		if (family == PF_INET) {
+			if (addrlen < sizeof(struct sockaddr_in)) {
+				err = -EINVAL;
+				goto out;
+			}
 			addr4 = (struct sockaddr_in *)address;
 			snum = ntohs(addr4->sin_port);
 			addrp = (char *)&addr4->sin_addr.s_addr;
+
 		} else {
+			if (addrlen < SIN6_LEN_RFC2133) {
+				err = -EINVAL;
+				goto out;
+			}
 			addr6 = (struct sockaddr_in6 *)address;
 			snum = ntohs(addr6->sin6_port);
 			addrp = (char *)&addr6->sin6_addr.s6_addr;
Acked-by: Eric Dumazet <edumazet@google.com>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help