Skip to contentSkip to conversation

xfrm: clear trailing padding in build_polexpire()

PATCH Applied Yasuaki Torimaru 4 participants 4 messages Mar 26 – Mar 31

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

PATCH v3 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 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 1da177e4c3f4 ("Linux-2.6.12-rc2")

---
v3:
- fix Fixes tag to cite the commit that introduced the bug
(was: e3e5fc1698ae which fixed the related build_expire() function)
v2: https://lore.kernel.org/netdev/[email protected]/
- add Fixes tag and Cc stable (requested by Steffen Klassert)
v1: https://lore.kernel.org/netdev/[email protected]/

 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 Reviewed-by on v3 1/1
#1 lore raw
Quoted 15 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.

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 1da177e4c3f4 ("Linux-2.6.12-rc2")
Quoted 7 lines

---
v3:
- fix Fixes tag to cite the commit that introduced the bug
(was: e3e5fc1698ae which fixed the related build_expire() function)
v2: https://lore.kernel.org/netdev/[email protected]/
- add Fixes tag and Cc stable (requested by Steffen Klassert)
v1: https://lore.kernel.org/netdev/[email protected]/

Thanks for the updates.

Reviewed-by on v3 1/1
#2 lore raw
In reply to Yasuaki Torimaru
Quoted 10 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.

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.

Quoted 5 lines

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

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
maintainer Applied
#3 lore raw
In reply to Yasuaki Torimaru
Quoted 10 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.

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.

Quoted 5 lines

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

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

Applied to the ipsec tree, thanks Yasuaki!