NET: catch signed nla_len() retval in tcf_simp_init()
Subsystems (3)
PATCH 1/1 NET: catch signed nla_len() retval in tcf_simp_init()
'datalen' is unsigned, use 'ret' instead to catch a negative return value.
---
net/sched/act_simple.c +3 -2
@@ -114,9 +114,10 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,if (defdata ==NULL )return -EINVAL ; - datalen =nla_len (tb[TCA_DEF_DATA ]); -if (datalen <=0 ) + ret =nla_len (tb[TCA_DEF_DATA ]); +if (ret <=0 )return -EINVAL ; + datalen = ret; pc =tcf_hash_check (parm->index, a, bind, &simp_hash_info);if (!pc) {
David Miller
maintainerFrom: Roel Kluin <[email protected]>
Date: Thu, 17 Apr 2008 05:33:21 +0200
Quoted 11 lines
'datalen' is unsigned, use 'ret' instead to catch a negative return value.
Signed-off-by Roel Kluin <[email protected]>---
net/sched/act_simple.c +0
-0@@ -114,9 +114,10 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,if (defdata ==NULL )return -EINVAL ;
net/sched/act_simple.c static int tcf_simp_init(struct nlattr *nla, struct nlattr *est, · line 123
Quoted 10 lines
net/sched/act_simple.c +3
-2- datalen =nla_len (tb[TCA_DEF_DATA ]); -if (datalen <=0 ) + ret =nla_len (tb[TCA_DEF_DATA ]); +if (ret <=0 )return -EINVAL ; + datalen = ret; pc =tcf_hash_check (parm->index, a, bind, &simp_hash_info);if (!pc) {
This clobbers 'ret' which is compared to ACT_P_CREATED later in the function. If the !pc branch below this code is not taken, ret must be left at it's initial value of zero. Now, it will take on some non-zero positive value which is not correct.
Quoted 22 lines · David Miller
From: Roel Kluin <[email protected]>
Date: Thu, 17 Apr 2008 05:33:21 +0200Quoted 19 lines
'datalen' is unsigned, use 'ret' instead to catch a negative return value.
Signed-off-by Roel Kluin <[email protected]>---
net/sched/act_simple.c +3
-2@@ -114,9 +114,10 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,if (defdata ==NULL )return -EINVAL ; - datalen =nla_len (tb[TCA_DEF_DATA ]); -if (datalen <=0 ) + ret =nla_len (tb[TCA_DEF_DATA ]); +if (ret <=0 )return -EINVAL ; + datalen = ret;
Quoted 8 lines
net/sched/act_simple.c static int tcf_simp_init(struct nlattr *nla, struct nlattr *est, · line 123
Quoted 2 lines
net/sched/act_simple.c +0
-0pc =tcf_hash_check (parm->index, a, bind, &simp_hash_info);if (!pc) {This clobbers 'ret' which is compared to
ACT_P_CREATEDlater in the function. If the !pc branch below this code is not taken, ret must be left at it's initial value of zero. Now, it will take on some non-zero positive value which is not correct.
The change is also unnecessary because the attribute was already validated and the length can not be less than zero.
This patch changes it to only check for zero length.
net/sched/act_simple.c +1 -1
@@ -115,7 +115,7 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,return -EINVAL ; datalen =nla_len (tb[TCA_DEF_DATA ]); -if (datalen <=0 ) +if (datalen ==0 )return -EINVAL ; pc =tcf_hash_check (parm->index, a, bind, &simp_hash_info);
Quoted 2 lines · Patrick McHardy
The change is also unnecessary because the attribute was already validated and the length can not be less than zero.
Since act_simple is an academic example:
I think that a better solution is to add TCA_DEF_DATA (which is a string) to the nla_policy. nla_policy is defined but at the moment it is not used in the call to nla_parse_nested() - might as well use it.
Roel, would you like to take a crack at that? You will need to define the max size of the string that TCA_DEF_DATA can hold (if you want to do it cleanly then define it in include/linux/tc_act/tc_defact.h). This MAX size will appear in the nla_policy.
cheers,
jamal
Quoted 9 lines · jamal
Quoted 2 lines · Patrick McHardy
The change is also unnecessary because the attribute was already validated and the length can not be less than zero.
Since
act_simpleis an academic example:
I think that a better solution is to addTCA_DEF_DATA(which is a string) to thenla_policy.nla_policyis defined but at the moment it is not used in the call tonla_parse_nested()- might as well use it.
Basic validity checks are always performed. But I agree, better to provide a good example.
Quoted 2 lines · Patrick McHardy
Basic validity checks are always performed. But I agree, better to provide a good example.
Thanks Patrick.
I just noticed the iproute2 piece is missing - probably sitting somewhere in my old laptop if i can find it.
Roel, you wanna take a crack at that too?
cheers,
jamal
David Miller
maintainerFrom: Patrick McHardy <[email protected]>
Date: Thu, 17 Apr 2008 06:55:35 +0200
Quoted 6 lines
The change is also unnecessary because the attribute was already validated and the length can not be less than zero.
This patch changes it to only check for zero length.
Signed-off-by Patrick McHardy <[email protected]>
Even though there have been discussions to do other things, this patch moves things in the forward direction so I have applied it.
Thanks.