Fix Warnining in arch/x86/kernel/signal.c
Hello Hiroshi-san,
Quoted 33 lines · On Thu, 2009-05-14 at 09:24 +0900, Hiroshi Shimamoto wrote: H. Peter Anvin…
Quoted 24 lines
Quoted 23 lines · Ingo Molnar
Quoted 23 lines
Quoted 13 lines
Review
Quoted 11 lines
(quoted diff) +4
-3if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) goto badframe; - if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1 - && __copy_from_user(&set.sig[1], &frame->extramask, - sizeof(frame->extramask)))) + + if ( (__copy_from_user(&set.sig[1], &frame->extramask, + sizeof(frame->extramask)) && _NSIG_WORDS > 1) || + __get_user(set.sig[0], &frame->sc.oldmask)) goto badframe;I'm not sure why this eliminates that warning.
set.sig[0] may not be initialized too, if__copy_from_user()failed.True, but only when either or both of
__copy_from_user()and (_NSIG_WORDS> 1) fails. But in all instances set.sig[1] gets initialized.Quoted 6 lines
I don't have enough time to look at this right now, sorry.
Another question,
__copy_from_user()will be called even if_NSIG_WORDSis less than 2, perhaps it never occurs.
I think, to check_NSIG_WORDS> 1 before calling__copy_from_user()is better.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Fine. Let Ingo/Thomas/Peter decide whether they would like this fix or drop it.
If you get the Acked-by from Hiroshi-san it looks good to me. He modified this code last.
This seriously looks wrong to me. If
_NSIG_WORDS== 1, then calling__copy_from_userhere is a serious error.
Quoted 8 lines
Right. If
_NSIG_WORDSis 1,sigset_tset has only sig[0], writing to set.sig[1] means stack corruption.Subrata, could you try like this?
if ((_NSIG_WORDS> 1 &&__copy_from_user(&set.sig[1], ...)||__get_user(set.sig[0], ...))
I tried out and the compiler does not complain in this case. Updated Patch below. Please review.
To: Hiroshi Shimamoto <[email protected]>,
Cc: H. Peter Anvin <[email protected]>,
Cc: Ingo Molnar <[email protected]>,
Cc: [email protected],
Cc: Sachin P Sant <[email protected]>,
Cc: Andi Kleen <[email protected]>,
Cc: Andi Kleen <[email protected]>,
Cc: Linux Kernel <[email protected]>,
Cc: Balbir Singh <[email protected]>,
Cc: Thomas Gleixner <[email protected]>,
Cc: Ingo Molnar <[email protected]>
Subject: Re:[PATCH] Fix Warnining in arch/x86/kernel/signal.c
---
arch/x86/kernel/signal.c +3 -3
@@ -576,9 +576,9 @@ unsigned long sys_sigreturn(struct pt_reif (!access_ok (VERIFY_READ , frame,sizeof (*frame))) goto badframe; -if (__get_user (set.sig[0 ], &frame->sc.oldmask) || (_NSIG_WORDS >1 - &&__copy_from_user (&set.sig[1 ], &frame->extramask, -sizeof (frame->extramask)))) +if ( (_NSIG_WORDS >1 &&__copy_from_user (&set.sig[1 ], + &frame->extramask,sizeof (frame->extramask))) || +__get_user (set.sig[0 ], &frame->sc.oldmask)) goto badframe;sigdelsetmask (&set, ~_BLOCKABLE);
---
Regards--
Subrata
Quoted 7 lines
I wonder whether gcc really complains about the case of
__get_user(set.sig[0], ...)failure.
Why, the case which sig[0] initialized and sig[1] uninitialized is NG and the case which sig[0] uninitialized and sig[1] initialized is OK.Thanks,
Hiroshi
Quoted 1 line · Subrata Modak
Hello Hiroshi-san,
Hi Subrata,
Quoted 37 lines · Hiroshi Shimamoto
Quoted 34 lines · H. Peter Anvin
Quoted 24 lines
Quoted 23 lines · Ingo Molnar
Quoted 23 lines
Quoted 13 lines
arch/x86/kernel/signal.c unsigned long sys_sigreturn(struct pt_re · line 582
Quoted 11 lines
arch/x86/kernel/signal.c +4
-3if (!access_ok (VERIFY_READ , frame,sizeof (*frame))) goto badframe; -if (__get_user (set.sig[0 ], &frame->sc.oldmask) || (_NSIG_WORDS >1 - &&__copy_from_user (&set.sig[1 ], &frame->extramask, -sizeof (frame->extramask)))) + +if ( (__copy_from_user (&set.sig[1 ], &frame->extramask, +sizeof (frame->extramask)) && _NSIG_WORDS >1 ) || +__get_user (set.sig[0 ], &frame->sc.oldmask)) goto badframe;I'm not sure why this eliminates that warning.
set.sig[0] may not be initialized too, if__copy_from_user()failed.True, but only when either or both of
__copy_from_user()and (_NSIG_WORDS> 1) fails. But in all instances set.sig[1] gets initialized.Quoted 6 lines
I don't have enough time to look at this right now, sorry.
Another question,
__copy_from_user()will be called even if_NSIG_WORDSis less than 2, perhaps it never occurs.
I think, to check_NSIG_WORDS> 1 before calling__copy_from_user()is better.Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Fine. Let Ingo/Thomas/Peter decide whether they would like this fix or drop it.
If you get the Acked-by from Hiroshi-san it looks good to me. He modified this code last.
This seriously looks wrong to me. If
_NSIG_WORDS== 1, then calling__copy_from_userhere is a serious error.Right. If
_NSIG_WORDSis 1,sigset_tset has only sig[0], writing to set.sig[1] means stack corruption.
Quoted 8 lines
Quoted 5 lines
Subrata, could you try like this?
if ((_NSIG_WORDS> 1 &&__copy_from_user(&set.sig[1], ...)||__get_user(set.sig[0], ...))I tried out and the compiler does not complain in this case. Updated Patch below. Please review.
thanks for testing, it looks OK except small nits. Could you please check with checkpatch.pl?
Quoted 2 lines
Signed-off-by Subrata Modak <[email protected]>
WARNING: Signed-off-by: is the preferred form
Quoted 17 lines
To: Hiroshi Shimamoto <[email protected]>,
Cc: H. Peter Anvin <[email protected]>,
Cc: Ingo Molnar <[email protected]>,
Cc: [email protected],
Cc: Sachin P Sant <[email protected]>,
Cc: Andi Kleen <[email protected]>,
Cc: Andi Kleen <[email protected]>,
Cc: Linux Kernel <[email protected]>,
Cc: Balbir Singh <[email protected]>,
Cc: Thomas Gleixner <[email protected]>,
Cc: Ingo Molnar <[email protected]>
Subject: Re:[PATCH] Fix Warnining inarch/x86/kernel/signal.c
---
arch/x86/kernel/signal.c unsigned long sys_sigreturn(struct pt_re · line 579
Quoted 7 lines
arch/x86/kernel/signal.c +1
-3@@ -576,9 +576,9 @@ unsigned long sys_sigreturn(struct pt_reif (!access_ok (VERIFY_READ , frame,sizeof (*frame))) goto badframe; -if (__get_user (set.sig[0 ], &frame->sc.oldmask) || (_NSIG_WORDS >1 - &&__copy_from_user (&set.sig[1 ], &frame->extramask, -sizeof (frame->extramask)))) + if ( (_NSIG_WORDS > 1 && __copy_from_user(&set.sig[1],
ERROR: space prohibited after that open parenthesis '('
arch/x86/kernel/signal.c unsigned long sys_sigreturn(struct pt_re · line 580
Quoted 1 line
arch/x86/kernel/signal.c +1
-0+ &frame->extramask, sizeof(frame->extramask))) ||
ERROR: code indent should use tabs where possible
arch/x86/kernel/signal.c unsigned long sys_sigreturn(struct pt_re · line 581
Quoted 1 line
arch/x86/kernel/signal.c +1
-0+ __get_user(set.sig[0], &frame->sc.oldmask))
ERROR: code indent should use tabs where possible
Thanks,
Hiroshi
Quoted 16 lines
arch/x86/kernel/signal.c +0
-1goto badframe;sigdelsetmask (&set, ~_BLOCKABLE); ---Regards--
SubrataQuoted 7 lines
I wonder whether gcc really complains about the case of
__get_user(set.sig[0], ...)failure.
Why, the case which sig[0] initialized and sig[1] uninitialized is NG and the case which sig[0] uninitialized and sig[1] initialized is OK.Thanks,
Hiroshi