diff mbox series

[net] ethtool: fix stack overflow in ethnl_parse_bitset()

Message ID 3487ee3a98e14cd526f55b6caaa959d2dcbcad9f.1607465316.git.mkubecek@suse.cz (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series [net] ethtool: fix stack overflow in ethnl_parse_bitset() | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Michal Kubecek Dec. 8, 2020, 10:13 p.m. UTC
Syzbot reported a stack overflow in bitmap_from_arr32() called from
ethnl_parse_bitset() when bitset from netlink message is longer than
target bitmap length. While ethnl_compact_sanity_checks() makes sure that
trailing part is all zeros (i.e. the request does not try to touch bits
kernel does not recognize), we also need to cap change_bits to nbits so
that we don't try to write past the prepared bitmaps.

Fixes: 88db6d1e4f62 ("ethtool: add ethnl_parse_bitset() helper")
Reported-by: syzbot+9d39fa49d4df294aab93@syzkaller.appspotmail.com
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 net/ethtool/bitset.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Jakub Kicinski Dec. 9, 2020, 11:55 p.m. UTC | #1
On Tue,  8 Dec 2020 23:13:51 +0100 (CET) Michal Kubecek wrote:
> Syzbot reported a stack overflow in bitmap_from_arr32() called from
> ethnl_parse_bitset() when bitset from netlink message is longer than
> target bitmap length. While ethnl_compact_sanity_checks() makes sure that
> trailing part is all zeros (i.e. the request does not try to touch bits
> kernel does not recognize), we also need to cap change_bits to nbits so
> that we don't try to write past the prepared bitmaps.
> 
> Fixes: 88db6d1e4f62 ("ethtool: add ethnl_parse_bitset() helper")
> Reported-by: syzbot+9d39fa49d4df294aab93@syzkaller.appspotmail.com
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>

Applied, thank you!
diff mbox series

Patch

diff --git a/net/ethtool/bitset.c b/net/ethtool/bitset.c
index 1fb3603d92ad..0515d6604b3b 100644
--- a/net/ethtool/bitset.c
+++ b/net/ethtool/bitset.c
@@ -628,6 +628,8 @@  int ethnl_parse_bitset(unsigned long *val, unsigned long *mask,
 			return ret;
 
 		change_bits = nla_get_u32(tb[ETHTOOL_A_BITSET_SIZE]);
+		if (change_bits > nbits)
+			change_bits = nbits;
 		bitmap_from_arr32(val, nla_data(tb[ETHTOOL_A_BITSET_VALUE]),
 				  change_bits);
 		if (change_bits < nbits)