LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] NET: catch signed nla_len() retval in tcf_simp_init()
@ 2008-04-17 3:33 Roel Kluin
2008-04-17 4:37 ` David Miller
0 siblings, 1 reply; 6+ messages in thread
From: Roel Kluin @ 2008-04-17 3:33 UTC (permalink / raw)
To: hadi, netdev, lkml
'datalen' is unsigned, use 'ret' instead to catch a negative return value.
Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
---
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index fbde461..b78d015 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -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) {
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] NET: catch signed nla_len() retval in tcf_simp_init()
2008-04-17 3:33 [PATCH] NET: catch signed nla_len() retval in tcf_simp_init() Roel Kluin
@ 2008-04-17 4:37 ` David Miller
2008-04-17 4:55 ` Patrick McHardy
0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2008-04-17 4:37 UTC (permalink / raw)
To: 12o3l; +Cc: hadi, netdev, linux-kernel
From: Roel Kluin <12o3l@tiscali.nl>
Date: Thu, 17 Apr 2008 05:33:21 +0200
> 'datalen' is unsigned, use 'ret' instead to catch a negative return value.
>
> Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
> ---
> diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
> index fbde461..b78d015 100644
> --- a/net/sched/act_simple.c
> +++ b/net/sched/act_simple.c
> @@ -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) {
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] NET: catch signed nla_len() retval in tcf_simp_init()
2008-04-17 4:37 ` David Miller
@ 2008-04-17 4:55 ` Patrick McHardy
2008-04-17 12:58 ` jamal
2008-04-18 6:20 ` David Miller
0 siblings, 2 replies; 6+ messages in thread
From: Patrick McHardy @ 2008-04-17 4:55 UTC (permalink / raw)
To: David Miller; +Cc: 12o3l, hadi, netdev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1274 bytes --]
David Miller wrote:
> From: Roel Kluin <12o3l@tiscali.nl>
> Date: Thu, 17 Apr 2008 05:33:21 +0200
>
>> 'datalen' is unsigned, use 'ret' instead to catch a negative return value.
>>
>> Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
>> ---
>> diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
>> index fbde461..b78d015 100644
>> --- a/net/sched/act_simple.c
>> +++ b/net/sched/act_simple.c
>> @@ -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) {
>
> 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.
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 <kaber@trash.net>
[-- Attachment #2: x --]
[-- Type: text/plain, Size: 417 bytes --]
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c
index fbde461..64b2d13 100644
--- a/net/sched/act_simple.c
+++ b/net/sched/act_simple.c
@@ -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);
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] NET: catch signed nla_len() retval in tcf_simp_init()
2008-04-17 4:55 ` Patrick McHardy
@ 2008-04-17 12:58 ` jamal
2008-04-17 13:10 ` Patrick McHardy
2008-04-18 6:20 ` David Miller
1 sibling, 1 reply; 6+ messages in thread
From: jamal @ 2008-04-17 12:58 UTC (permalink / raw)
To: Patrick McHardy; +Cc: David Miller, 12o3l, netdev, linux-kernel
On Thu, 2008-17-04 at 06:55 +0200, Patrick McHardy wrote:
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] NET: catch signed nla_len() retval in tcf_simp_init()
2008-04-17 12:58 ` jamal
@ 2008-04-17 13:10 ` Patrick McHardy
0 siblings, 0 replies; 6+ messages in thread
From: Patrick McHardy @ 2008-04-17 13:10 UTC (permalink / raw)
To: hadi; +Cc: David Miller, 12o3l, netdev, linux-kernel
jamal wrote:
> On Thu, 2008-17-04 at 06:55 +0200, Patrick McHardy wrote:
>
>> 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.
Basic validity checks are always performed. But I agree, better
to provide a good example.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] NET: catch signed nla_len() retval in tcf_simp_init()
2008-04-17 4:55 ` Patrick McHardy
2008-04-17 12:58 ` jamal
@ 2008-04-18 6:20 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2008-04-18 6:20 UTC (permalink / raw)
To: kaber; +Cc: 12o3l, hadi, netdev, linux-kernel
From: Patrick McHardy <kaber@trash.net>
Date: Thu, 17 Apr 2008 06:55:35 +0200
> 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 <kaber@trash.net>
Even though there have been discussions to do other things,
this patch moves things in the forward direction so I have
applied it.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-04-18 6:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-17 3:33 [PATCH] NET: catch signed nla_len() retval in tcf_simp_init() Roel Kluin
2008-04-17 4:37 ` David Miller
2008-04-17 4:55 ` Patrick McHardy
2008-04-17 12:58 ` jamal
2008-04-17 13:10 ` Patrick McHardy
2008-04-18 6:20 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).