PKT_SCHED: validate policer configuration TLVs
Subsystems (3)
PATCH 1/1 PKT_SCHED: validate policer configuration TLVs
Adds TLV size sanity checks for policer configuration.
net/sched/police.c +20 -6
@@ -180,7 +180,8 @@if (rtattr_parse (tb,TCA_POLICE_MAX ,RTA_DATA (rta),RTA_PAYLOAD (rta)) <0 )return -1 ; -if (tb[TCA_POLICE_TBF -1 ] ==NULL ) +if (tb[TCA_POLICE_TBF -1 ] ==NULL || +RTA_PAYLOAD (tb[TCA_POLICE_TBF -1 ]) !=sizeof (*parm))return -1 ; parm =RTA_DATA (tb[TCA_POLICE_TBF -1 ]);
@@ -220,11 +221,17 @@ goto failure; } } -if (tb[TCA_POLICE_RESULT -1 ]) +if (tb[TCA_POLICE_RESULT -1 ]) { +if (RTA_PAYLOAD (tb[TCA_POLICE_RESULT -1 ]) !=sizeof (u32)) + goto failure; p->result = *(int *)RTA_DATA (tb[TCA_POLICE_RESULT -1 ]); + }#ifdef CONFIG_NET_ESTIMATOR -if (tb[TCA_POLICE_AVRATE -1 ]) +if (tb[TCA_POLICE_AVRATE -1 ]) { +if (RTA_PAYLOAD (tb[TCA_POLICE_AVRATE -1 ]) !=sizeof (u32)) + goto failure; p->ewma_rate = *(u32 *)RTA_DATA (tb[TCA_POLICE_AVRATE -1 ]); + }#endif p->toks = p->burst = parm->burst; p->mtu = parm->mtu;
@@ -424,7 +431,8 @@if (rtattr_parse (tb,TCA_POLICE_MAX ,RTA_DATA (rta),RTA_PAYLOAD (rta)) <0 )return NULL ; -if (tb[TCA_POLICE_TBF -1 ] ==NULL ) +if (tb[TCA_POLICE_TBF -1 ] ==NULL || +RTA_PAYLOAD (tb[TCA_POLICE_TBF -1 ]) !=sizeof (*parm))return NULL ; parm =RTA_DATA (tb[TCA_POLICE_TBF -1 ]);
@@ -449,11 +457,17 @@ (p->P_tab = qdisc_get_rtab(&parm->peakrate, tb[TCA_POLICE_PEAKRATE-1])) == NULL) goto failure; } -if (tb[TCA_POLICE_RESULT -1 ]) +if (tb[TCA_POLICE_RESULT -1 ]) { +if (RTA_PAYLOAD (tb[TCA_POLICE_RESULT -1 ]) !=sizeof (u32)) + goto failure; p->result = *(int *)RTA_DATA (tb[TCA_POLICE_RESULT -1 ]); + }#ifdef CONFIG_NET_ESTIMATOR -if (tb[TCA_POLICE_AVRATE -1 ]) +if (tb[TCA_POLICE_AVRATE -1 ]) { +if (RTA_PAYLOAD (tb[TCA_POLICE_AVRATE -1 ]) !=sizeof (u32)) + goto failure; p->ewma_rate = *(u32 *)RTA_DATA (tb[TCA_POLICE_AVRATE -1 ]); + }#endif p->toks = p->burst = parm->burst; p->mtu = parm->mtu;
David S. Miller
maintainerQuoted 1 line · On Tue, 7 Dec 2004 18:23:49 +0100 Thomas Graf <[email protected]> wrote:
Adds TLV size sanity checks for policer configuration.
Hmmm...
net/sched/police.c line 228
Quoted 6 lines
net/sched/police.c +4
-1-if (tb[TCA_POLICE_RESULT -1 ]) +if (tb[TCA_POLICE_RESULT -1 ]) { +if (RTA_PAYLOAD (tb[TCA_POLICE_RESULT -1 ]) !=sizeof (u32)) + goto failure; p->result = *(int *)RTA_DATA (tb[TCA_POLICE_RESULT -1 ]); + }
Either these things are int's or u32's, they cannot be both :-) I know that size wise it's identical, but at least make the code look consistent.
PATCH 1/1 PKT_SCHED: validate policer configuration TLVs
Quoted 3 lines
Either these things are int's or u32's, they cannot be both :-) I know that size wise it's identical, but at least make the code look consistent.
OK, I changed the dereferencing to use u32 as well and have it "casted" while assigning the value since changing the structure datatypes wouldn't make sense.
net/sched/police.c +22 -8
@@ -180,7 +180,8 @@if (rtattr_parse (tb,TCA_POLICE_MAX ,RTA_DATA (rta),RTA_PAYLOAD (rta)) <0 )return -1 ; -if (tb[TCA_POLICE_TBF -1 ] ==NULL ) +if (tb[TCA_POLICE_TBF -1 ] ==NULL || +RTA_PAYLOAD (tb[TCA_POLICE_TBF -1 ]) !=sizeof (*parm))return -1 ; parm =RTA_DATA (tb[TCA_POLICE_TBF -1 ]);
@@ -220,11 +221,17 @@ goto failure; } } -if (tb[TCA_POLICE_RESULT -1 ]) - p->result = *(int *)RTA_DATA (tb[TCA_POLICE_RESULT -1 ]); +if (tb[TCA_POLICE_RESULT -1 ]) { +if (RTA_PAYLOAD (tb[TCA_POLICE_RESULT -1 ]) !=sizeof (u32)) + goto failure; + p->result = *(u32 *)RTA_DATA (tb[TCA_POLICE_RESULT -1 ]); + }#ifdef CONFIG_NET_ESTIMATOR -if (tb[TCA_POLICE_AVRATE -1 ]) +if (tb[TCA_POLICE_AVRATE -1 ]) { +if (RTA_PAYLOAD (tb[TCA_POLICE_AVRATE -1 ]) !=sizeof (u32)) + goto failure; p->ewma_rate = *(u32 *)RTA_DATA (tb[TCA_POLICE_AVRATE -1 ]); + }#endif p->toks = p->burst = parm->burst; p->mtu = parm->mtu;
@@ -424,7 +431,8 @@if (rtattr_parse (tb,TCA_POLICE_MAX ,RTA_DATA (rta),RTA_PAYLOAD (rta)) <0 )return NULL ; -if (tb[TCA_POLICE_TBF -1 ] ==NULL ) +if (tb[TCA_POLICE_TBF -1 ] ==NULL || +RTA_PAYLOAD (tb[TCA_POLICE_TBF -1 ]) !=sizeof (*parm))return NULL ; parm =RTA_DATA (tb[TCA_POLICE_TBF -1 ]);
@@ -449,11 +457,17 @@ (p->P_tab = qdisc_get_rtab(&parm->peakrate, tb[TCA_POLICE_PEAKRATE-1])) == NULL) goto failure; } -if (tb[TCA_POLICE_RESULT -1 ]) - p->result = *(int *)RTA_DATA (tb[TCA_POLICE_RESULT -1 ]); +if (tb[TCA_POLICE_RESULT -1 ]) { +if (RTA_PAYLOAD (tb[TCA_POLICE_RESULT -1 ]) !=sizeof (u32)) + goto failure; + p->result = *(u32 *)RTA_DATA (tb[TCA_POLICE_RESULT -1 ]); + }#ifdef CONFIG_NET_ESTIMATOR -if (tb[TCA_POLICE_AVRATE -1 ]) +if (tb[TCA_POLICE_AVRATE -1 ]) { +if (RTA_PAYLOAD (tb[TCA_POLICE_AVRATE -1 ]) !=sizeof (u32)) + goto failure; p->ewma_rate = *(u32 *)RTA_DATA (tb[TCA_POLICE_AVRATE -1 ]); + }#endif p->toks = p->burst = parm->burst; p->mtu = parm->mtu;
Quoted 9 lines · On Wed, 8 Dec 2004 21:39:42 +0100 Thomas Graf <[email protected]> wrote:
Quoted 3 lines
Either these things are int's or u32's, they cannot be both :-) I know that size wise it's identical, but at least make the code look consistent.
OK, I changed the dereferencing to use u32 as well and have it "casted" while assigning the value since changing the structure datatypes wouldn't make sense.
Signed-off-by Thomas Graf <[email protected]>
Applied, thanks Thomas.