netfilter: ebtables: fix OOB read in compat_mtw_from_user
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 netfilter: ebtables: fix OOB read in compat_mtw_from_user
From: Luxiao Xu <[email protected]>
The function compat_mtw_from_user() converts ebtables extensions from 32-bit user structures to kernel native structures. However, it lacks proper validation of the user-supplied match_size/target_size.
When certain extensions are processed, the kernel-side translation logic may perform memory accesses based on the extension's expected size. If the user provides a size smaller than what the extension requires, it results in an out-of-bounds read as reported by KASAN.
This fix introduces a check to ensure match_size is at least as large as the extension's required compatsize. This covers matches, watchers, and targets, while maintaining compatibility with standard targets.
--- net/bridge/netfilter/ebtables.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
net/bridge/netfilter/ebtables.c +11 -0
@@ -1977,6 +1977,11 @@ static int compat_mtw_from_user(const struct compat_ebt_entry_mwt *mwt,if (IS_ERR (match))return PTR_ERR (match); +if (match_size < match->compatsize) { +module_put (match->me); +return -EINVAL ; + } + off =ebt_compat_match_offset (match, match_size);if (dst) {if (match->compat_from_user)
@@ -1996,6 +2001,12 @@ static int compat_mtw_from_user(const struct compat_ebt_entry_mwt *mwt, mwt->u.revision);if (IS_ERR (wt))return PTR_ERR (wt); + +if (match_size < wt->compatsize) { +module_put (wt->me); +return -EINVAL ; + } + off =xt_compat_target_offset (wt);if (dst) {
Signature · 1 line
2.43.0
Florian Westphal
maintainerQuoted 32 lines · Ren Wei
From: Luxiao Xu <[email protected]>
The function
compat_mtw_from_user()converts ebtables extensions from 32-bit user structures to kernel native structures. However, it lacks proper validation of the user-supplied match_size/target_size.When certain extensions are processed, the kernel-side translation logic may perform memory accesses based on the extension's expected size. If the user provides a size smaller than what the extension requires, it results in an out-of-bounds read as reported by KASAN.
This fix introduces a check to ensure
match_sizeis at least as large as the extension's required compatsize. This covers matches, watchers, and targets, while maintaining compatibility with standard targets.Fixes 81e675c227ec ("netfilter: ebtables: add CONFIG_COMPAT support")Reported-by Yuan Tan <[email protected]>Reported-by Yifan Wu <[email protected]>Reported-by Juefei Pu <[email protected]>Reported-by Xin Liu <[email protected]>Signed-off-by Luxiao Xu <[email protected]>Signed-off-by Ren Wei <[email protected]>--- net/bridge/netfilter/ebtables.c | 11 +++++++++++ 1 file changed, 11 insertions(+)net/bridge/netfilter/ebtables.c +0
-0
net/bridge/netfilter/ebtables.c static int compat_mtw_from_user(const struct compat_ebt_entry_mwt *mwt, · line 1984
Quoted 8 lines
net/bridge/netfilter/ebtables.c +5
-0@@ -1977,6 +1977,11 @@ static int compat_mtw_from_user(const struct compat_ebt_entry_mwt *mwt,if (IS_ERR (match))return PTR_ERR (match); +if (match_size < match->compatsize) { +module_put (match->me); +return -EINVAL ; + } +
Are you sure this catches all bad requests? AFAIR compatsize is 0 in most cases, which bypasses this test.
should this be:
u16 csize = match->compatsize ? : match->matchsize;
...
if (match_size < csize) {
...
?
@Pablo: I think the 32bit compat layer should be removed in -next, or at least strongly discouraged and slated for removal soon.