net: sched: act_ife: initialize struct tc_ife to fix KMSAN kernel-infoleak
Subsystems (3)
v2 cover net: sched: act_ife: initialize struct tc_ife to fix KMSAN kernel-infoleak
Fix a KMSAN kernel-infoleak detected by the syzbot .
[net?] KMSAN: kernel-infoleak in __skb_datagram_iter
In tcf_ife_dump(), the variable 'opt' was partially initialized using a designatied initializer. While the padding bytes are reamined uninitialized. nla_put() copies the entire structure into a netlink message, these uninitialized bytes leaked to userspace.
Initialize the structure with memset before assigning its fields to ensure all members and padding are cleared prior to beign copied.
---
Changes in v2:
- removed memset(&t, 0, sizeof(t)) from previous patch.
- added the new patch series to address the issue.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Ranganath V N (2):
net: sched: act_ife: initialize struct tc_ife to fix KMSAN kernel-infoleak
net: sched: act_connmark: zero initialize the struct to avoid KMSAN
net/sched/act_connmark.c | 12 +++++++----- net/sched/act_ife.c | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-)
---
base-commit: d127176862a93c4b3216bda533d2bee170af5e71
change-id: 20251031-infoleak-8a7de6afc987
Best regards,
Signature · 1 line
Ranganath V N <[email protected]>
PATCH v2 1/2 net: sched: act_ife: initialize struct tc_ife to fix KMSAN kernel-infoleak
Fix a KMSAN kernel-infoleak detected by the syzbot .
[net?] KMSAN: kernel-infoleak in __skb_datagram_iter
In tcf_ife_dump(), the variable 'opt' was partially initialized using a designatied initializer. While the padding bytes are reamined uninitialized. nla_put() copies the entire structure into a netlink message, these uninitialized bytes leaked to userspace.
Initialize the structure with memset before assigning its fields to ensure all members and padding are cleared prior to beign copied.
This change silences the KMSAN report and prevents potential information leaks from the kernel memory.
This fix has been tested and validated by syzbot. This patch closes the bug reported at the following syzkaller link and ensures no infoleak.
--- net/sched/act_ife.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
net/sched/act_ife.c +7 -5
@@ -644,13 +644,15 @@ static int tcf_ife_dump(struct sk_buff *skb, struct tc_action *a, int bind,unsigned char *b =skb_tail_pointer (skb);struct tcf_ife_info *ife =to_ife (a);struct tcf_ife_params *p; -struct tc_ife opt = { - .index = ife->tcf_index, - .refcnt =refcount_read (&ife->tcf_refcnt) - ref, - .bindcnt =atomic_read (&ife->tcf_bindcnt) - bind, - }; +struct tc_ife opt;struct tcf_t t; +memset (&opt,0 ,sizeof (opt)); + + opt.index = ife->tcf_index, + opt.refcnt =refcount_read (&ife->tcf_refcnt) - ref, + opt.bindcnt =atomic_read (&ife->tcf_bindcnt) - bind, +spin_lock_bh (&ife->tcf_lock); opt.action = ife->tcf_action; p = rcu_dereference_protected(ife->params,
Signature · 1 line
2.43.0
PATCH v2 2/2 net: sched: act_connmark: zero initialize the struct to avoid KMSAN
In reply to Ranganath V Nzero initialize the struct to avoid the infoleak to the userspace.
--- net/sched/act_connmark.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
net/sched/act_connmark.c +7 -5
@@ -195,13 +195,15 @@ static inline int tcf_connmark_dump(struct sk_buff *skb, struct tc_action *a,const struct tcf_connmark_info *ci =to_connmark (a);unsigned char *b =skb_tail_pointer (skb);const struct tcf_connmark_parms *parms; -struct tc_connmark opt = { - .index = ci->tcf_index, - .refcnt =refcount_read (&ci->tcf_refcnt) - ref, - .bindcnt =atomic_read (&ci->tcf_bindcnt) - bind, - }; +struct tc_connmark opt;struct tcf_t t; +memset (&opt,0 ,sizeof (opt)); + + opt.index = ci->tcf_index, + opt.refcnt =refcount_read (&ci->tcf_refcnt) - ref, + opt.bindcnt =atomic_read (&ci->tcf_bindcnt) - bind, +rcu_read_lock (); parms =rcu_dereference (ci->parms);
Signature · 1 line
2.43.0
Simon Horman
reviewerQuoted 11 lines · Ranganath V N
Fix a KMSAN kernel-infoleak detected by the syzbot .
[net?] KMSAN: kernel-infoleak in
__skb_datagram_iterIn
tcf_ife_dump(), the variable 'opt' was partially initialized using a designatied initializer. While the padding bytes are reamined uninitialized.nla_put()copies the entire structure into a netlink message, these uninitialized bytes leaked to userspace.Initialize the structure with memset before assigning its fields to ensure all members and padding are cleared prior to beign copied.
Perhaps not important, but this seems to only describe patch 1/2.
Quoted 2 lines
Signed-off-by Ranganath V N <[email protected]>
Sorry for not looking more carefully at v1.
The presence of this padding seems pretty subtle to me. And while I agree that your change fixes the problem described. I wonder if it would be better to make things more obvious by adding a 2-byte pad member to the structures involved.
...
Simon Horman
reviewerQuoted 38 lines · Ranganath V N
Fix a KMSAN kernel-infoleak detected by the syzbot .
[net?] KMSAN: kernel-infoleak in
__skb_datagram_iterIn
tcf_ife_dump(), the variable 'opt' was partially initialized using a designatied initializer. While the padding bytes are reamined uninitialized.nla_put()copies the entire structure into a netlink message, these uninitialized bytes leaked to userspace.Initialize the structure with memset before assigning its fields to ensure all members and padding are cleared prior to beign copied.
This change silences the KMSAN report and prevents potential information leaks from the kernel memory.
This fix has been tested and validated by syzbot. This patch closes the bug reported at the following syzkaller link and ensures no infoleak.
Reported-by [email protected]Tested-by [email protected]Fixes ef6980b6becb ("introduce IFE action")Signed-off-by Ranganath V N <[email protected]>--- net/sched/act_ife.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)net/sched/act_ife.c +0
-3@@ -644,13 +644,15 @@ static int tcf_ife_dump(struct sk_buff *skb, struct tc_action *a, int bind,unsigned char *b =skb_tail_pointer (skb);struct tcf_ife_info *ife =to_ife (a);struct tcf_ife_params *p; -struct tc_ife opt = { - .index = ife->tcf_index, - .refcnt =refcount_read (&ife->tcf_refcnt) - ref,
net/sched/act_ife.c static int tcf_ife_dump(struct sk_buff *skb, struct tc_action *a, int bind, · line 654
Quoted 10 lines
net/sched/act_ife.c +6
-2- .bindcnt = atomic_read(&ife->tcf_bindcnt) - bind, - }; +struct tc_ife opt;struct tcf_t t; +memset (&opt,0 ,sizeof (opt)); + + opt.index = ife->tcf_index, + opt.refcnt =refcount_read (&ife->tcf_refcnt) - ref, + opt.bindcnt = atomic_read(&ife->tcf_bindcnt) - bind,
I don't think it makes any difference to the compiled code. But I think it would be clearer to use ';' rather than ',' at the end of each of the three lines above.
Likewise in patch 2/2.
Quoted 8 lines
net/sched/act_ife.c +1
-0+spin_lock_bh (&ife->tcf_lock); opt.action = ife->tcf_action; p = rcu_dereference_protected(ife->params,Signature · 2 lines
-- 2.43.0
Quoted 16 lines · Simon Horman
Quoted 11 lines · Ranganath V N
Fix a KMSAN kernel-infoleak detected by the syzbot .
[net?] KMSAN: kernel-infoleak in
__skb_datagram_iterIn
tcf_ife_dump(), the variable 'opt' was partially initialized using a designatied initializer. While the padding bytes are reamined uninitialized.nla_put()copies the entire structure into a netlink message, these uninitialized bytes leaked to userspace.Initialize the structure with memset before assigning its fields to ensure all members and padding are cleared prior to beign copied.
Perhaps not important, but this seems to only describe patch 1/2.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Signed-off-by Ranganath V N <[email protected]>Sorry for not looking more carefully at v1.
The presence of this padding seems pretty subtle to me. And while I agree that your change fixes the problem described. I wonder if it would be better to make things more obvious by adding a 2-byte pad member to the structures involved.
Thanks for the input.
One question — even though adding a 2-byte pad field silences KMSAN, would that approach be reliable across all architectures?
Since the actual amount and placement of padding can vary depending on structure alignment and compiler behavior, I’m wondering if this would only silence the report on certain builds rather than fixing the root cause.
The current memset-based initialization explicitly clears all bytes in the structure (including any compiler-inserted padding), which seems safer and more consistent across architectures.
Also, adding a new member — even a padding field — could potentially alter the structure size or layout as seen from user space. That might unintentionally affect existing user-space expectations.
Do you think relying on a manual pad field is good enough?
regards,
--Ranganath
Simon Horman
reviewerQuoted 38 lines · Ranganath V N
Quoted 16 lines · Simon Horman
Quoted 11 lines · Ranganath V N
Fix a KMSAN kernel-infoleak detected by the syzbot .
[net?] KMSAN: kernel-infoleak in
__skb_datagram_iterIn
tcf_ife_dump(), the variable 'opt' was partially initialized using a designatied initializer. While the padding bytes are reamined uninitialized.nla_put()copies the entire structure into a netlink message, these uninitialized bytes leaked to userspace.Initialize the structure with memset before assigning its fields to ensure all members and padding are cleared prior to beign copied.
Perhaps not important, but this seems to only describe patch 1/2.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Signed-off-by Ranganath V N <[email protected]>Sorry for not looking more carefully at v1.
The presence of this padding seems pretty subtle to me. And while I agree that your change fixes the problem described. I wonder if it would be better to make things more obvious by adding a 2-byte pad member to the structures involved.
Thanks for the input.
One question — even though adding a 2-byte
padfield silences KMSAN, would that approach be reliable across all architectures?
Since the actual amount and placement of padding can vary depending on structure alignment and compiler behavior, I’m wondering if this would only silence the report on certain builds rather than fixing the root cause.The current memset-based initialization explicitly clears all bytes in the structure (including any compiler-inserted padding), which seems safer and more consistent across architectures.
Quoted 5 lines
Also, adding a new member — even a padding field — could potentially alter the structure size or layout as seen from user space. That might unintentionally affect existing user-space expectations.
Do you think relying on a manual pad field is good enough?
I think these are the right questions to ask.
My thinking is that structures will be padded to a multiple of either 4 or 8 bytes, depending on the architecture.
And my observation is that that the unpadded length of both of the structures in question are 22 bytes. And that on x86_64 they are padded to 24 bytes. Which is divisible by both 4 and 8. So I assume this will be consistent for all architectures. If so, I think this would address the questions you raised.
I do, however, agree that your current memset-based approach is safer in the sense that it carries a lower risk of breaking things because it has fewer assumptions (that we have thought of so far).
Jamal Hadi Salim
maintainerQuoted 57 lines · Simon Horman
Quoted 38 lines · Ranganath V N
Quoted 16 lines · Simon Horman
Quoted 11 lines · Ranganath V N
Fix a KMSAN kernel-infoleak detected by the syzbot .
[net?] KMSAN: kernel-infoleak in
__skb_datagram_iterIn
tcf_ife_dump(), the variable 'opt' was partially initialized using a designatied initializer. While the padding bytes are reamined uninitialized.nla_put()copies the entire structure into a netlink message, these uninitialized bytes leaked to userspace.Initialize the structure with memset before assigning its fields to ensure all members and padding are cleared prior to beign copied.
Perhaps not important, but this seems to only describe patch 1/2.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Signed-off-by Ranganath V N <[email protected]>Sorry for not looking more carefully at v1.
The presence of this padding seems pretty subtle to me. And while I agree that your change fixes the problem described. I wonder if it would be better to make things more obvious by adding a 2-byte pad member to the structures involved.
Thanks for the input.
One question — even though adding a 2-byte
padfield silences KMSAN, would that approach be reliable across all architectures?
Since the actual amount and placement of padding can vary depending on structure alignment and compiler behavior, I’m wondering if this would only silence the report on certain builds rather than fixing the root cause.The current memset-based initialization explicitly clears all bytes in the structure (including any compiler-inserted padding), which seems safer and more consistent across architectures.
Quoted 5 lines
Also, adding a new member — even a padding field — could potentially alter the structure size or layout as seen from user space. That might unintentionally affect existing user-space expectations.
Do you think relying on a manual pad field is good enough?
I think these are the right questions to ask.
My thinking is that structures will be padded to a multiple of either 4 or 8 bytes, depending on the architecture.
And my observation is that that the unpadded length of both of the structures in question are 22 bytes. And that on
x86_64they are padded to 24 bytes. Which is divisible by both 4 and 8. So I assume this will be consistent for all architectures. If so, I think this would address the questions you raised.
Quoted 3 lines
I do, however, agree that your current memset-based approach is safer in the sense that it carries a lower risk of breaking things because it has fewer assumptions (that we have thought of so far).
+1
My view is lets fix the immediate leak issue with the memset, and a subsequent patch can add the padding if necessary.
cheers,
jamal
Simon Horman
reviewerQuoted 58 lines · Jamal Hadi Salim
Quoted 57 lines · Simon Horman
Quoted 38 lines · Ranganath V N
Quoted 16 lines · Simon Horman
Quoted 11 lines · Ranganath V N
Fix a KMSAN kernel-infoleak detected by the syzbot .
[net?] KMSAN: kernel-infoleak in
__skb_datagram_iterIn
tcf_ife_dump(), the variable 'opt' was partially initialized using a designatied initializer. While the padding bytes are reamined uninitialized.nla_put()copies the entire structure into a netlink message, these uninitialized bytes leaked to userspace.Initialize the structure with memset before assigning its fields to ensure all members and padding are cleared prior to beign copied.
Perhaps not important, but this seems to only describe patch 1/2.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Signed-off-by Ranganath V N <[email protected]>Sorry for not looking more carefully at v1.
The presence of this padding seems pretty subtle to me. And while I agree that your change fixes the problem described. I wonder if it would be better to make things more obvious by adding a 2-byte pad member to the structures involved.
Thanks for the input.
One question — even though adding a 2-byte
padfield silences KMSAN, would that approach be reliable across all architectures?
Since the actual amount and placement of padding can vary depending on structure alignment and compiler behavior, I’m wondering if this would only silence the report on certain builds rather than fixing the root cause.The current memset-based initialization explicitly clears all bytes in the structure (including any compiler-inserted padding), which seems safer and more consistent across architectures.
Quoted 5 lines
Also, adding a new member — even a padding field — could potentially alter the structure size or layout as seen from user space. That might unintentionally affect existing user-space expectations.
Do you think relying on a manual pad field is good enough?
I think these are the right questions to ask.
My thinking is that structures will be padded to a multiple of either 4 or 8 bytes, depending on the architecture.
And my observation is that that the unpadded length of both of the structures in question are 22 bytes. And that on
x86_64they are padded to 24 bytes. Which is divisible by both 4 and 8. So I assume this will be consistent for all architectures. If so, I think this would address the questions you raised.
Quoted 7 lines
Quoted 3 lines
I do, however, agree that your current memset-based approach is safer in the sense that it carries a lower risk of breaking things because it has fewer assumptions (that we have thought of so far).
+1
My view is lets fix the immediate leak issue with the memset, and a subsequent patch can add the padding if necessary.
Sure, no objections from my side.
Quoted 63 lines · Simon Horman
Quoted 62 lines · Jamal Hadi Salim
Quoted 60 lines · Simon Horman
Quoted 38 lines · Ranganath V N
Quoted 16 lines · Simon Horman
Quoted 11 lines · Ranganath V N
Fix a KMSAN kernel-infoleak detected by the syzbot .
[net?] KMSAN: kernel-infoleak in
__skb_datagram_iterIn
tcf_ife_dump(), the variable 'opt' was partially initialized using a designatied initializer. While the padding bytes are reamined uninitialized.nla_put()copies the entire structure into a netlink message, these uninitialized bytes leaked to userspace.Initialize the structure with memset before assigning its fields to ensure all members and padding are cleared prior to beign copied.
Perhaps not important, but this seems to only describe patch 1/2.
Quoted 1 line
Quoted 8 lines
Quoted 1 line
Signed-off-by Ranganath V N <[email protected]>Sorry for not looking more carefully at v1.
The presence of this padding seems pretty subtle to me. And while I agree that your change fixes the problem described. I wonder if it would be better to make things more obvious by adding a 2-byte pad member to the structures involved.
Thanks for the input.
One question — even though adding a 2-byte
padfield silences KMSAN, would that approach be reliable across all architectures?
Since the actual amount and placement of padding can vary depending on structure alignment and compiler behavior, I’m wondering if this would only silence the report on certain builds rather than fixing the root cause.The current memset-based initialization explicitly clears all bytes in the structure (including any compiler-inserted padding), which seems safer and more consistent across architectures.
Quoted 5 lines
Also, adding a new member — even a padding field — could potentially alter the structure size or layout as seen from user space. That might unintentionally affect existing user-space expectations.
Do you think relying on a manual pad field is good enough?
I think these are the right questions to ask.
My thinking is that structures will be padded to a multiple of either 4 or 8 bytes, depending on the architecture.
And my observation is that that the unpadded length of both of the structures in question are 22 bytes. And that on
x86_64they are padded to 24 bytes. Which is divisible by both 4 and 8. So I assume this will be consistent for all architectures. If so, I think this would address the questions you raised.I do, however, agree that your current memset-based approach is safer in the sense that it carries a lower risk of breaking things because it has fewer assumptions (that we have thought of so far).
Quoted 5 lines
Quoted 3 lines
+1
My view is lets fix the immediate leak issue with the memset, and a subsequent patch can add the padding if necessary.Sure, no objections from my side.
Thanks for the clarification.
I'll send the new patch series(v3) with fix(missed ;)
I'll keep the current change limited to the memset fix to resolve the issue. Also, I've noticed that similar uninitialized structure patterns exist in a few other locations in the net code.
Thanks for the review.