vsprintf: Prevent NULL dereference using %pNF
Subsystems (2)
PATCH 1/1 vsprintf: Prevent NULL dereference using %pNF
Passing NULL to %pNF is done in skb_gso_segment which could be dereferenced.
Add noinline_for_stack to function.
Make pointer argument the actual type. Check pointer for NULL and use 0 when so.
--- lib/vsprintf.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
lib/vsprintf.c +12 -4
@@ -777,16 +777,24 @@ char *uuid_string(char *buf, char *end, const u8 *addr,return string (buf, end, uuid, spec); } -static -char *netdev_feature_string (char *buf,char *end,const u8 *addr, -struct printf_spec spec) +static noinline_for_stack +char *netdev_feature_string(char *buf, char *end, +const netdev_features_t *features, +struct printf_spec spec) { +unsigned long long num; + +if (features) + num = (unsigned long long )*features; +else + num =0 ; + spec.flags |=SPECIAL |SMALL |ZEROPAD ;if (spec.field_width ==-1 ) spec.field_width =2 +2 *sizeof (netdev_features_t); spec.base =16 ; -return number (buf, end, *(const netdev_features_t *)addr, spec); +return number (buf, end, num, spec); }int kptr_restrict__read_mostly ;
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:37:13 -0800
Quoted 2 lines
Passing NULL to %pNF is done in
skb_gso_segment
which could be dereferenced.
skb_gso_segment() should be fixed instead.
Quoted 5 lines · David Miller
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:37:13 -0800Quoted 2 lines
Passing NULL to %pNF is done in
skb_gso_segment
which could be dereferenced.
skb_gso_segment()should be fixed instead.
Maybe. Dereferencing NULL is bad form. Michał Mirosław should fix that as it's his patch.
noinline_for_stack should be added anyway.
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:51:13 -0800
Quoted 8 lines · David Miller
Quoted 5 lines
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:37:13 -0800Quoted 2 lines
Passing NULL to %pNF is done in
skb_gso_segment
which could be dereferenced.
skb_gso_segment()should be fixed instead.Maybe. Dereferencing NULL is bad form.
We don't check for NULL for IPV4 or IPV6 addresses, no reason to treat this any differently.
Either do it for all %pX things, or none of them.
Quoted 6 lines · David Miller
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:51:13 -0800Quoted 3 lines · David Miller
Quoted 2 lines
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:37:13 -0800
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Passing NULL to %pNF is done in
skb_gso_segment
which could be dereferenced.
skb_gso_segment()should be fixed instead.Maybe. Dereferencing NULL is bad form.
We don't check for NULL for IPV4 or IPV6 addresses,
Because we don't pass NULL addresses.
Quoted 2 lines
no reason
to treat this any differently.
A NULL address is specifically passed here.
Quoted 1 line
Either do it for all %pX things, or none of them.
Maybe.
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:54:56 -0800
Quoted 6 lines · David Miller
Quoted 3 lines
From: Joe Perches <[email protected]>
no reason
to treat this any differently.A NULL address is specifically passed here.
And I said fix that skb_gso_whatever case, because it's wrong.
Quoted 8 lines · Joe Perches
Quoted 5 lines · David Miller
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:37:13 -0800Quoted 2 lines
Passing NULL to %pNF is done in
skb_gso_segment
which could be dereferenced.
skb_gso_segment()should be fixed instead.Maybe. Dereferencing NULL is bad form. Michał Mirosław should fix that as it's his patch.
Will do. This is in WARN() and easily fixed.
Quoted 1 line
noinline_for_stackshould be added anyway.
Why? There are no local variables there and inlining this function would actually save stack space as no stack frame would be created for the call.
Best Regards,
Michał Mirosław
Quoted 10 lines · Michał Mirosław
Quoted 8 lines · Joe Perches
Quoted 5 lines · David Miller
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:37:13 -0800Quoted 2 lines
Passing NULL to %pNF is done in
skb_gso_segment
which could be dereferenced.
skb_gso_segment()should be fixed instead.Maybe. Dereferencing NULL is bad form. Michał Mirosław should fix that as it's his patch.
Quoted 6 lines
Will do. This is in
WARN()and easily fixed.Quoted 1 line
noinline_for_stackshould be added anyway.Why? There are no local variables there and inlining this function would actually save stack space as no stack frame would be created for the call.
Isn't an additional copy of "struct printf_spec spec" on the stack in function pointer() now?
Quoted 10 lines · Joe Perches
Quoted 9 lines · Michał Mirosław
Quoted 8 lines · Joe Perches
Quoted 5 lines · David Miller
From: Joe Perches <[email protected]>
Date: Tue, 17 Jan 2012 10:37:13 -0800Quoted 2 lines
Passing NULL to %pNF is done in
skb_gso_segment
which could be dereferenced.
skb_gso_segment()should be fixed instead.Maybe. Dereferencing NULL is bad form. Michał Mirosław should fix that as it's his patch.
Quoted 8 lines
Quoted 6 lines
Will do. This is in
WARN()and easily fixed.Quoted 1 line
noinline_for_stackshould be added anyway.Why? There are no local variables there and inlining this function would actually save stack space as no stack frame would be created for the call.
Isn't an additional copy of "struct
printf_specspec" on the stack in functionpointer()now?
If the function is inlined then gcc should know that original is not needed after call and do no copy. Without inlining, gcc should too, optimize it because it's a tail call.
We could read the generated assembly to be sure, of course.
Best Regards,
Michał Mirosław
Quoted 7 lines · Michał Mirosław
Quoted 2 lines · Joe Perches
Isn't an additional copy of "struct
printf_specspec" on the stack in functionpointer()now?If the function is inlined then gcc should know that original is not needed after call and do no copy. Without inlining, gcc should too, optimize it because it's a tail call.
We could read the generated assembly to be sure, of course.
At least for x86/gcc 4.6, it seems it doesn't make any difference.