Skip to contentSkip to conversation

net: fib_rules: add FRA_GOTO and FRA_L3MDEV to fib_rule_nlmsg_size()

PATCH In review Linkui Xiao 2 participants 4 messages Sep 11 – Sep 15

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: fib_rules: add FRA_GOTO and FRA_L3MDEV to fib_rule_nlmsg_size()

From: Linkui Xiao <[email protected]>

fib_nl_fill_rule() emits FRA_GOTO and FRA_L3MDEV, but fib_rule_nlmsg_size() reserves room for neither. Its only caller, notify_rule_change(), allocates the notification skb with that size and treats a failure as a bug:

	/* -EMSGSIZE implies BUG in fib_rule_nlmsg_size() */

A rule that has both a goto target and l3mdev set needs 16 more bytes than are reserved. nlmsg_new() rounds the allocation up through SKB_DATA_ALIGN(), so the slack hides the mistake most of the time and the bug stays latent, but the accounting is wrong and the notification can still fail with -EMSGSIZE.

Reserve the two missing attributes, keeping the order used by fib_nl_fill_rule().

Fixes 0947c9fe56d9 ("[NET] fib_rules: goto rule action")
Fixes 96c63fa7393d ("net: Add l3mdev rule")
---
 net/core/fib_rules.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/fib_rules.c +2 -0
index 7df216c17c67..5e84bc740191 100644
@@ -1133,7 +1133,9 @@ static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
 			 + nla_total_size(4) /* FRA_SUPPRESS_IFGROUP */
 			 + nla_total_size(4) /* FRA_FWMARK */
 			 + nla_total_size(4) /* FRA_FWMASK */
+			 + nla_total_size(4) /* FRA_GOTO */
 			 + nla_total_size_64bit(8) /* FRA_TUN_ID */
+			 + nla_total_size(1) /* FRA_L3MDEV */
 			 + nla_total_size(sizeof(struct fib_kuid_range))
 			 + nla_total_size(1) /* FRA_PROTOCOL */
 			 + nla_total_size(1) /* FRA_IP_PROTO */
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 8 lines · Linkui Xiao

From: Linkui Xiao <[email protected]>

fib_nl_fill_rule() emits FRA_GOTO and FRA_L3MDEV, but fib_rule_nlmsg_size() reserves room for neither. Its only caller, notify_rule_change(), allocates the notification skb with that size and treats a failure as a bug:

	/* -EMSGSIZE implies BUG in fib_rule_nlmsg_size() */

not really going to fail since the size has so many attributes that are not applicable to this rule.

Quoted 31 lines

A rule that has both a goto target and l3mdev set needs 16 more bytes than are reserved. nlmsg_new() rounds the allocation up through SKB_DATA_ALIGN(), so the slack hides the mistake most of the time and the bug stays latent, but the accounting is wrong and the notification can still fail with -EMSGSIZE.

Reserve the two missing attributes, keeping the order used by fib_nl_fill_rule().

Fixes 0947c9fe56d9 ("[NET] fib_rules: goto rule action")
Fixes 96c63fa7393d ("net: Add l3mdev rule")
---
 net/core/fib_rules.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/fib_rules.c +2 -0
index 7df216c17c67..5e84bc740191 100644
@@ -1133,7 +1133,9 @@ static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
 			 + nla_total_size(4) /* FRA_SUPPRESS_IFGROUP */
 			 + nla_total_size(4) /* FRA_FWMARK */
 			 + nla_total_size(4) /* FRA_FWMASK */
+			 + nla_total_size(4) /* FRA_GOTO */
 			 + nla_total_size_64bit(8) /* FRA_TUN_ID */
+			 + nla_total_size(1) /* FRA_L3MDEV */
 			 + nla_total_size(sizeof(struct fib_kuid_range))
 			 + nla_total_size(1) /* FRA_PROTOCOL */
 			 + nla_total_size(1) /* FRA_IP_PROTO */
#2 lore raw
Quoted 11 lines · David Ahern
Quoted 8 lines · Linkui Xiao

From: Linkui Xiao <[email protected]>

fib_nl_fill_rule() emits FRA_GOTO and FRA_L3MDEV, but fib_rule_nlmsg_size() reserves room for neither. Its only caller, notify_rule_change(), allocates the notification skb with that size and treats a failure as a bug:

	/* -EMSGSIZE implies BUG in fib_rule_nlmsg_size() */

not really going to fail since the size has so many attributes that are not applicable to this rule.

You are right, the other attributes reserved in fib_rule_nlmsg_size() already provide more than enough slack for the common case, so the missing FRA_GOTO/FRA_L3MDEV accounting cannot actually overflow the skb.

I will drop this patch. Thanks for taking the time to review it.

Thanks,
Linkui Xiao

Quoted 31 lines
Quoted 31 lines

A rule that has both a goto target and l3mdev set needs 16 more bytes than are reserved. nlmsg_new() rounds the allocation up through SKB_DATA_ALIGN(), so the slack hides the mistake most of the time and the bug stays latent, but the accounting is wrong and the notification can still fail with -EMSGSIZE.

Reserve the two missing attributes, keeping the order used by fib_nl_fill_rule().

Fixes 0947c9fe56d9 ("[NET] fib_rules: goto rule action")
Fixes 96c63fa7393d ("net: Add l3mdev rule")
---
  net/core/fib_rules.c | 2 ++
  1 file changed, 2 insertions(+)
net/core/fib_rules.c +2 -0
index 7df216c17c67..5e84bc740191 100644
@@ -1133,7 +1133,9 @@ static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
  			 + nla_total_size(4) /* FRA_SUPPRESS_IFGROUP */
  			 + nla_total_size(4) /* FRA_FWMARK */
  			 + nla_total_size(4) /* FRA_FWMASK */
+			 + nla_total_size(4) /* FRA_GOTO */
  			 + nla_total_size_64bit(8) /* FRA_TUN_ID */
+			 + nla_total_size(1) /* FRA_L3MDEV */
  			 + nla_total_size(sizeof(struct fib_kuid_range))
  			 + nla_total_size(1) /* FRA_PROTOCOL */
  			 + nla_total_size(1) /* FRA_IP_PROTO */
#3 lore raw
In reply to David Ahern
Quoted 8 lines · David Ahern
Quoted 7 lines · Linkui Xiao

From: Linkui Xiao <[email protected]>

fib_nl_fill_rule() emits FRA_GOTO and FRA_L3MDEV, but fib_rule_nlmsg_size() reserves room for neither. Its only caller, notify_rule_change(), allocates the notification skb with that size and treats a failure as a bug:

Quoted 5 lines
Quoted 1 line
	/* -EMSGSIZE implies BUG in fib_rule_nlmsg_size() */

not really going to fail since the size has so many attributes that are not applicable to this rule.

You are right, the other attributes reserved in fib_rule_nlmsg_size() already provide more than enough slack for the common case, so the missing FRA_GOTO/FRA_L3MDEV accounting cannot actually overflow the skb.

I will drop this patch. Thanks for taking the time to review it.

Thanks,
Linkui Xiao

Quoted 32 lines
Quoted 31 lines

A rule that has both a goto target and l3mdev set needs 16 more bytes than are reserved. nlmsg_new() rounds the allocation up through SKB_DATA_ALIGN(), so the slack hides the mistake most of the time and the bug stays latent, but the accounting is wrong and the notification can still fail with -EMSGSIZE.

Reserve the two missing attributes, keeping the order used by fib_nl_fill_rule().

Fixes 0947c9fe56d9 ("[NET] fib_rules: goto rule action")
Fixes 96c63fa7393d ("net: Add l3mdev rule")
---
  net/core/fib_rules.c | 2 ++
  1 file changed, 2 insertions(+)
net/core/fib_rules.c +2 -0
index 7df216c17c67..5e84bc740191 100644
@@ -1133,7 +1133,9 @@ static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
  			 + nla_total_size(4) /* FRA_SUPPRESS_IFGROUP */
  			 + nla_total_size(4) /* FRA_FWMARK */
  			 + nla_total_size(4) /* FRA_FWMASK */
+			 + nla_total_size(4) /* FRA_GOTO */
  			 + nla_total_size_64bit(8) /* FRA_TUN_ID */
+			 + nla_total_size(1) /* FRA_L3MDEV */
  			 + nla_total_size(sizeof(struct fib_kuid_range))
  			 + nla_total_size(1) /* FRA_PROTOCOL */
  			 + nla_total_size(1) /* FRA_IP_PROTO */