diff mbox series

[v1] net/sched: act_pedit: Add size check for TCA_PEDIT_PARMS_EX

Message ID 20230703110842.590282-1-linma@zju.edu.cn (mailing list archive)
State Accepted
Commit 30c45b5361d39b4b793780ffac5538090b9e2eb1
Delegated to: Netdev Maintainers
Headers show
Series [v1] net/sched: act_pedit: Add size check for TCA_PEDIT_PARMS_EX | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers fail 2 blamed authors not CCed: ogerlitz@mellanox.com amir@vadai.me; 2 maintainers not CCed: ogerlitz@mellanox.com amir@vadai.me
netdev/build_clang fail Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Lin Ma July 3, 2023, 11:08 a.m. UTC
The attribute TCA_PEDIT_PARMS_EX is not be included in pedit_policy and
one malicious user could fake a TCA_PEDIT_PARMS_EX whose length is
smaller than the intended sizeof(struct tc_pedit). Hence, the
dereference in tcf_pedit_init() could access dirty heap data.

static int tcf_pedit_init(...)
{
  // ...
  pattr = tb[TCA_PEDIT_PARMS]; // TCA_PEDIT_PARMS is included
  if (!pattr)
    pattr = tb[TCA_PEDIT_PARMS_EX]; // but this is not

  // ...
  parm = nla_data(pattr);

  index = parm->index; // parm is able to be smaller than 4 bytes
                       // and this dereference gets dirty skb_buff
                       // data created in netlink_sendmsg
}

This commit adds TCA_PEDIT_PARMS_EX length in pedit_policy which avoid
the above case, just like the TCA_PEDIT_PARMS.

Fixes: 71d0ed7079df ("net/act_pedit: Support using offset relative to the conventional network headers")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
---
 net/sched/act_pedit.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Pedro Tammela July 3, 2023, 2:21 p.m. UTC | #1
On 03/07/2023 08:08, Lin Ma wrote:
> The attribute TCA_PEDIT_PARMS_EX is not be included in pedit_policy and
> one malicious user could fake a TCA_PEDIT_PARMS_EX whose length is
> smaller than the intended sizeof(struct tc_pedit). Hence, the
> dereference in tcf_pedit_init() could access dirty heap data.
> 
> static int tcf_pedit_init(...)
> {
>    // ...
>    pattr = tb[TCA_PEDIT_PARMS]; // TCA_PEDIT_PARMS is included
>    if (!pattr)
>      pattr = tb[TCA_PEDIT_PARMS_EX]; // but this is not
> 
>    // ...
>    parm = nla_data(pattr);
> 
>    index = parm->index; // parm is able to be smaller than 4 bytes
>                         // and this dereference gets dirty skb_buff
>                         // data created in netlink_sendmsg
> }
> 
> This commit adds TCA_PEDIT_PARMS_EX length in pedit_policy which avoid
> the above case, just like the TCA_PEDIT_PARMS.
> 
> Fixes: 71d0ed7079df ("net/act_pedit: Support using offset relative to the conventional network headers")
> Signed-off-by: Lin Ma <linma@zju.edu.cn>

LGTM,

Reviewed-by: Pedro Tammela <pctammela@mojatatu.com>

> ---
>   net/sched/act_pedit.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
> index b562fc2bb5b1..1ef8fcfa9997 100644
> --- a/net/sched/act_pedit.c
> +++ b/net/sched/act_pedit.c
> @@ -29,6 +29,7 @@ static struct tc_action_ops act_pedit_ops;
>   
>   static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
>   	[TCA_PEDIT_PARMS]	= { .len = sizeof(struct tc_pedit) },
> +	[TCA_PEDIT_PARMS_EX]	= { .len = sizeof(struct tc_pedit) },
>   	[TCA_PEDIT_KEYS_EX]   = { .type = NLA_NESTED },
>   };
>
patchwork-bot+netdevbpf@kernel.org July 4, 2023, 12:50 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Mon,  3 Jul 2023 19:08:42 +0800 you wrote:
> The attribute TCA_PEDIT_PARMS_EX is not be included in pedit_policy and
> one malicious user could fake a TCA_PEDIT_PARMS_EX whose length is
> smaller than the intended sizeof(struct tc_pedit). Hence, the
> dereference in tcf_pedit_init() could access dirty heap data.
> 
> static int tcf_pedit_init(...)
> {
>   // ...
>   pattr = tb[TCA_PEDIT_PARMS]; // TCA_PEDIT_PARMS is included
>   if (!pattr)
>     pattr = tb[TCA_PEDIT_PARMS_EX]; // but this is not
> 
> [...]

Here is the summary with links:
  - [v1] net/sched: act_pedit: Add size check for TCA_PEDIT_PARMS_EX
    https://git.kernel.org/netdev/net/c/30c45b5361d3

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index b562fc2bb5b1..1ef8fcfa9997 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -29,6 +29,7 @@  static struct tc_action_ops act_pedit_ops;
 
 static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
 	[TCA_PEDIT_PARMS]	= { .len = sizeof(struct tc_pedit) },
+	[TCA_PEDIT_PARMS_EX]	= { .len = sizeof(struct tc_pedit) },
 	[TCA_PEDIT_KEYS_EX]   = { .type = NLA_NESTED },
 };