Skip to contentSkip to conversation

xfrm: clear trailing padding in build_polexpire()

PATCH Superseded Yasuaki Torimaru 3 participants 6 messages Mar 21 – Mar 26

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfrm: clear trailing padding in build_polexpire()

build_expire() clears the trailing padding bytes of struct xfrm_user_expire after setting the hard field via memset_after(), but the analogous function build_polexpire() does not do this for struct xfrm_user_polexpire.

The 7 bytes of padding after the __u8 hard field are left uninitialized from the heap allocation, and are then sent to userspace via netlink multicast to XFRMNLGRP_EXPIRE listeners, leaking kernel heap memory contents.

Add the missing memset_after() call, matching build_expire().

---
 net/xfrm/xfrm_user.c | 2 ++
 1 file changed, 2 insertions(+)
net/xfrm/xfrm_user.c +2 -0
index 403b5ecac..ee31ef482 100644
@@ -3948,6 +3948,8 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
 		return err;
 	}
 	upe->hard = !!hard;
+	/* clear the padding bytes */
+	memset_after(upe, 0, hard);
 
 	nlmsg_end(skb, nlh);
 	return 0;
Signature · 1 line
2.50.1
maintainer
#1 lore raw
Quoted 5 lines · Yasuaki Torimaru

build_expire() clears the trailing padding bytes of struct xfrm_user_expire after setting the hard field via memset_after(), but the analogous function build_polexpire() does not do this for struct xfrm_user_polexpire.

Quoted 8 lines

The 7 bytes of padding after the __u8 hard field are left uninitialized from the heap allocation, and are then sent to userspace via netlink multicast to XFRMNLGRP_EXPIRE listeners, leaking kernel heap memory contents.

Add the missing memset_after() call, matching build_expire().

Can you please add a 'Fixes:' tag, so it can be backported?

Thanks!

#2 lore raw

PATCH v2 1/1 xfrm: clear trailing padding in build_polexpire()

In reply to Yasuaki Torimaru

build_expire() clears the trailing padding bytes of struct xfrm_user_expire after setting the hard field via memset_after(), but the analogous function build_polexpire() does not do this for struct xfrm_user_polexpire.

The padding bytes after the __u8 hard field are left uninitialized from the heap allocation, and are then sent to userspace via netlink multicast to XFRMNLGRP_EXPIRE listeners, leaking kernel heap memory contents.

Add the missing memset_after() call, matching build_expire().

Fixes e3e5fc1698ae ("xfrm_user: fix info leak in build_expire()")

---
Verified with pahole (struct xfrm_user_polexpire):

- x86_64:       sizeof=176, padding=7
- i386:         sizeof=168, padding=3
- aarch64:      sizeof=176, padding=7
- armv7l (hf):  sizeof=176, padding=7
 net/xfrm/xfrm_user.c | 2 ++
 1 file changed, 2 insertions(+)
net/xfrm/xfrm_user.c +2 -0
index 403b5ecac2c5..ee31ef482be4 100644
@@ -3948,6 +3948,8 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
 		return err;
 	}
 	upe->hard = !!hard;
+	/* clear the padding bytes */
+	memset_after(upe, 0, hard);
 
 	nlmsg_end(skb, nlh);
 	return 0;
Signature · 1 line
2.50.1
reviewer
#3 lore raw
Quoted 5 lines · Yasuaki Torimaru

build_expire() clears the trailing padding bytes of struct xfrm_user_expire after setting the hard field via memset_after(), but the analogous function build_polexpire() does not do this for struct xfrm_user_polexpire.

Quoted 8 lines

The padding bytes after the __u8 hard field are left uninitialized from the heap allocation, and are then sent to userspace via netlink multicast to XFRMNLGRP_EXPIRE listeners, leaking kernel heap memory contents.

Add the missing memset_after() call, matching build_expire().

Fixes e3e5fc1698ae ("xfrm_user: fix info leak in build_expire()")

I think the Fixes tag should cite the patch that introduced the bug. The commit cited above looks like a related fix, but no the cause of the bug.

Quoted 27 lines

---
Verified with pahole (struct xfrm_user_polexpire):

- x86_64:       sizeof=176, padding=7
- i386:         sizeof=168, padding=3
- aarch64:      sizeof=176, padding=7
- armv7l (hf):  sizeof=176, padding=7
 net/xfrm/xfrm_user.c | 2 ++
 1 file changed, 2 insertions(+)
net/xfrm/xfrm_user.c +2 -0
index 403b5ecac2c5..ee31ef482be4 100644
@@ -3948,6 +3948,8 @@ static int build_polexpire(struct sk_buff *skb, struct xfrm_policy *xp,
 		return err;
 	}
 	upe->hard = !!hard;
+	/* clear the padding bytes */
+	memset_after(upe, 0, hard);
 
 	nlmsg_end(skb, nlh);
 	return 0;
Signature · 1 line
2.50.1
#4 lore raw
Quoted 2 lines · Simon Horman

I think the Fixes tag should cite the patch that introduced the bug. The commit cited above looks like a related fix, but no the cause of the bug.

You're right. build_polexpire() has existed since the initial import (1da177e4c3f4), so the padding has been uninitialized from the beginning. Sending v3 with the corrected Fixes tag.

#5 lore raw
In reply to Simon Horman
Quoted 2 lines · Simon Horman

I think the Fixes tag should cite the patch that introduced the bug. The commit cited above looks like a related fix, but no the cause of the bug.

You're right. build_polexpire() has existed since the initial import (1da177e4c3f4), so the padding has been uninitialized from the beginning. Sending v3 with the corrected Fixes tag.