Skip to contentSkip to conversation

ethtool: strset: Fix out of bound read in strset_parse_request()

PATCH In review Anmol Karn 2 participants 3 messages Oct 10, 2020 – Oct 11, 2020

Subsystems (3)
lore
Share & tools
lore

Anmol Karn

author
#0 lore raw

PATCH 1/1 ethtool: strset: Fix out of bound read in strset_parse_request()

Flag ``ETHTOOL_A_STRSET_COUNTS_ONLY`` tells the kernel to only return the string counts of the sets, but, when req_info->counts_only tries to read the tb[ETHTOOL_A_STRSET_COUNTS_ONLY] it gets out of bound.

- net/ethtool/strset.c
The bug seems to trigger in this line:

req_info->counts_only = tb[ETHTOOL_A_STRSET_COUNTS_ONLY];

Fix it by NULL checking for req_info->counts_only while reading from tb[ETHTOOL_A_STRSET_COUNTS_ONLY].

---
When I tried to reduce the index of tb[] by 1, the crash reproducer was not working anymore, hence it's probably reading from tb[ETHTOOL_A_STRSET_STRINGSETS], but this won't give the strset 'count' and hence is not a plausible fix. But checking for the req_info->counts_only seems legit.

If I have missed something please let me know, and I will work towards fixing it in next version.

 net/ethtool/strset.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ethtool/strset.c +2 -1
index 82707b662fe4..20a7b36698f3 100644
@@ -174,7 +174,8 @@ static int strset_parse_request(struct ethnl_req_info *req_base,
 	if (ret < 0)
 		return ret;
 
-	req_info->counts_only = tb[ETHTOOL_A_STRSET_COUNTS_ONLY];
+	if (req_info->counts_only)
+		req_info->counts_only = tb[ETHTOOL_A_STRSET_COUNTS_ONLY];
 	nla_for_each_nested(attr, nest, rem) {
 		u32 id;
 
Signature · 5 lines
2.28.0
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
maintainer
#1 lore raw
Quoted 7 lines · On Sun, 11 Oct 2020 02:39:29 +0530 Anmol Karn wrote:

Flag ``ETHTOOL_A_STRSET_COUNTS_ONLY`` tells the kernel to only return the string counts of the sets, but, when req_info->counts_only tries to read the tb[ETHTOOL_A_STRSET_COUNTS_ONLY] it gets out of bound.

- net/ethtool/strset.c
The bug seems to trigger in this line:

Quoted 8 lines

req_info->counts_only = tb[ETHTOOL_A_STRSET_COUNTS_ONLY];

Fix it by NULL checking for req_info->counts_only while reading from tb[ETHTOOL_A_STRSET_COUNTS_ONLY].

I think the correct fix for this was already applied to net-next as:

commit db972e532518 ("ethtool: strset: allow ETHTOOL_A_STRSET_COUNTS_ONLY attr")

author
#2 lore raw

Hello sir,

Quoted 14 lines · Jakub Kicinski
Quoted 12 lines · On Sun, 11 Oct 2020 02:39:29 +0530 Anmol Karn wrote:

Flag ``ETHTOOL_A_STRSET_COUNTS_ONLY`` tells the kernel to only return the string counts of the sets, but, when req_info->counts_only tries to read the tb[ETHTOOL_A_STRSET_COUNTS_ONLY] it gets out of bound.

- net/ethtool/strset.c
The bug seems to trigger in this line:

req_info->counts_only = tb[ETHTOOL_A_STRSET_COUNTS_ONLY];

Fix it by NULL checking for req_info->counts_only while reading from tb[ETHTOOL_A_STRSET_COUNTS_ONLY].

Quoted 7 lines
Quoted 3 lines

I think the correct fix for this was already applied to net-next as:

commit db972e532518 ("ethtool: strset: allow ETHTOOL_A_STRSET_COUNTS_ONLY attr")

I am glad that it's fixed now.

Thanks,
Anmol