Skip to contentSkip to conversation

Catch wrong RTATTR_MAX with BUG()

PATCH In review Thomas Graf 3 participants 3 messages Sep 9, 2004

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

PATCH 1/1 Catch wrong RTATTR_MAX with BUG()

Catches outdated/invalid RTATTR_MAX and therefore avoids possible stack corruption.

net/core/rtnetlink.c +3 -0
@@ -450,6 +450,9 @@
 	sz_idx = type>>2;
 	kind = type&3;
 
+	if (RTATTR_MAX < rta_max[sz_idx])
+		BUG();
+
 	if (kind != 2 && security_netlink_recv(skb)) {
 		*errp = -EPERM;
 		return -1;
maintainer
#1 lore raw
Quoted 2 lines · On Thu, 9 Sep 2004 18:43:46 +0200 Thomas Graf <[email protected]> wrote:

Catches outdated/invalid RTATTR_MAX and therefore avoids possible stack corruption.

Your test has an off by one error, but more importantly, it's probably better to do this at compile time with something like:

extern void rtattr_max_too_small(void);

...

void __init rtnetlink_init(void)

{
	if (IFLA_MAX > RTATTR_MAX ||
	    IFA_MAX > RTATTR_MAX ||
	    RTA_MAX > RTATTR_MAX ||
	    NDA_MAX > RTATTR_MAX ||
	    TCA_MAX > RTATTR_MAX ||
	    TCAA_MAX > RTATTR_MAX)
		rtattr_max_too_small();

I would therefore accept a patch that did things this way. BUG()'ing at runtime for something like this is too rude. :)

Thanks.

#2 lore raw
In reply to Thomas Graf

In article <[email protected]> (at Thu, 9 Sep 2004 18:43:46 +0200), Thomas Graf <[email protected]> says:

net/core/rtnetlink.c line 455

Quoted 5 lines
net/core/rtnetlink.c +3 -0
 	kind = type&3;
 
+	if (RTATTR_MAX < rta_max[sz_idx])
+		BUG();
+

Something like:

	if (rta_max[sz_idx] > RTATTR_MAX)
		goto err_inval;
Signature · 2 lines
Hideaki YOSHIFUJI @ USAGI Project <[email protected]>
GPG FP: 9022 65EB 1ECF 3AD1 0BDF  80D8 4807 F894 E062 0EEA