xfrm: clear trailing padding in build_polexpire()
Subsystems (4)
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
@@ -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
Steffen Klassert
maintainerQuoted 5 lines · Yasuaki Torimaru
build_expire()clears the trailing padding bytes of structxfrm_user_expireafter setting the hard field viamemset_after(), but the analogous functionbuild_polexpire()does not do this for structxfrm_user_polexpire.
Quoted 8 lines
The 7 bytes of padding after the
__u8hard field are left uninitialized from the heap allocation, and are then sent to userspace via netlink multicast toXFRMNLGRP_EXPIRElisteners, leaking kernel heap memory contents.Add the missing
memset_after()call, matchingbuild_expire().Signed-off-by Yasuaki Torimaru <[email protected]>
Can you please add a 'Fixes:' tag, so it can be backported?
Thanks!
PATCH v2 1/1 xfrm: clear trailing padding in build_polexpire()
In reply to Yasuaki Torimarubuild_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().
---
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
@@ -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
Simon Horman
reviewerQuoted 5 lines · Yasuaki Torimaru
build_expire()clears the trailing padding bytes of structxfrm_user_expireafter setting the hard field viamemset_after(), but the analogous functionbuild_polexpire()does not do this for structxfrm_user_polexpire.
Quoted 8 lines
The padding bytes after the
__u8hard field are left uninitialized from the heap allocation, and are then sent to userspace via netlink multicast toXFRMNLGRP_EXPIRElisteners, leaking kernel heap memory contents.Add the missing
memset_after()call, matchingbuild_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
Signed-off-by Yasuaki Torimaru <[email protected]>---
Verified with pahole (structxfrm_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@@ -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
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.
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.