Skip to contentSkip to conversation

kernel memory leak fix for af_unix datagram getpeersec

PATCH Catherine Zhang 3 participants 3 messages Jul 16, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi, Catalin and Michal,

Enclosed please find the patch against 2.6.18-rc1 that fixed the kernel memory leak problem.

Thanks for your help!
Catherine

--

From: [email protected]
Fix the memory leak problem of the original unix datagram getpeersec patch.

---

 include/net/scm.h      |    4 +++-
 net/ipv4/ip_sockglue.c |    1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
include/net/scm.h renamed from include/net/scm.h~af_unix-datagram-getpeersec-ml-fix +3 -1
diff -puN include/net/scm.h~af_unix-datagram-getpeersec-ml-fix include/net/scm.h
@@ -55,8 +55,10 @@ static __inline__ int scm_send(struct so
 #ifdef CONFIG_SECURITY_NETWORK
 static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm)
 {
-	if (test_bit(SOCK_PASSSEC, &sock->flags) && scm->secdata != NULL)
+	if (test_bit(SOCK_PASSSEC, &sock->flags) && scm->secdata != NULL) {
 		put_cmsg(msg, SOL_SOCKET, SCM_SECURITY, scm->seclen, scm->secdata);
+		kfree(scm->secdata);
+	}
 }
 #else
 static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm)
net/ipv4/ip_sockglue.c renamed from net/ipv4/ip_sockglue.c~af_unix-datagram-getpeersec-ml-fix +1 -0
diff -puN net/ipv4/ip_sockglue.c~af_unix-datagram-getpeersec-ml-fix net/ipv4/ip_sockglue.c
@@ -120,6 +120,7 @@ static void ip_cmsg_recv_security(struct
 		return;
 
 	put_cmsg(msg, SOL_IP, SCM_SECURITY, seclen, secdata);
+	kfree(secdata);
 }
 
 

_

#1 lore raw
Quoted 5 lines · Catherine Zhang

Hi, Catalin and Michal,

Enclosed please find the patch against 2.6.18-rc1 that fixed the kernel memory leak problem.

The core kernel code doesn't know anything about secdata, as it is up to the LSM to determine what it is (in the case of SELinux, a kmalloc'd buffer).

So, you need a cleanup hook which allows the LSM to free the secdata if required.

- James

Signature · 2 lines
James Morris
<[email protected]>
#2 lore raw
In reply to Catherine Zhang

Hi Catherine,

Quoted 5 lines · Catherine Zhang

Hi, Catalin and Michal,

Enclosed please find the patch against 2.6.18-rc1 that fixed the kernel memory leak problem.

I still get a lot of memory leak reports.

[michal@ltg01-fedora ~]$ cat /tmp/ml1.txt | grep -c selinux_socket_getpeersec_dgram
802
[michal@ltg01-fedora ~]$ cat /tmp/ml2.txt | grep -c selinux_socket_getpeersec_dgram
816

Quoted 3 lines

Thanks for your help!
Catherine

Regards,
Michal

Signature · 3 lines
Michal K. K. Piotrowski
LTG - Linux Testers Group
(http://www.stardust.webpages.pl/ltg/wiki/)