2013-03-15 21:16:16

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH] x86: remove the x32 syscall bitmask from syscall_get_nr()

On Tuesday, February 26, 2013 03:58:23 PM Paul Moore wrote:
> On Friday, February 15, 2013 12:21:43 PM Paul Moore wrote:
> > Commit fca460f95e928bae373daa8295877b6905bc62b8 simplified the x32
> > implementation by creating a syscall bitmask, equal to 0x40000000, that
> > could be applied to x32 syscalls such that the masked syscall number
> > would be the same as a x86_64 syscall. While that patch was a nice
> > way to simplify the code, it went a bit too far by adding the mask to
> > syscall_get_nr(); returning the masked syscall numbers can cause
> > confusion with callers that expect syscall numbers matching the x32
> > ABI, e.g. unmasked syscall numbers.
> >
> > This patch fixes this by simply removing the mask from syscall_get_nr()
> > while preserving the other changes from the original commit. While
> > there are several syscall_get_nr() callers in the kernel, most simply
> > check that the syscall number is greater than zero, in this case this
> > patch will have no effect. Of those remaining callers, they appear
> > to be few, seccomp and ftrace, and from my testing of seccomp without
> > this patch the original commit definitely breaks things; the seccomp
> > filter does not correctly filter the syscalls due to the difference in
> > syscall numbers in the BPF filter and the value from syscall_get_nr().
> > Applying this patch restores the seccomp BPF filter functionality on
> > x32.
> >
> > I've tested this patch with the seccomp BPF filters as well as ftrace
> > and everything looks reasonable to me; needless to say general usage
> > seemed fine as well.
>
> I just wanted to check and see where things stood with this patch. I'm not
> overly concerned about how this problem is solved, just that it is solved.
> If someone else has a better approach that is fine with me; I'll even make
> the offer to do additional testing if needed.

Anyone? The seccomp filter bits are completely broken on x32 and I'd like to
get this fixed, if not with this patch then something else - I'm more than
happy to test/verify/etc whatever solution is deemed best ...

> > Signed-off-by: Paul Moore <[email protected]>
> > Cc: [email protected]
> > Cc: Will Drewry <[email protected]>
> > Cc: H. Peter Anvin <[email protected]>
> > ---
> >
> > arch/x86/include/asm/syscall.h | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/syscall.h
> > b/arch/x86/include/asm/syscall.h index 1ace47b..2e188d6 100644
> > --- a/arch/x86/include/asm/syscall.h
> > +++ b/arch/x86/include/asm/syscall.h
> > @@ -29,13 +29,13 @@ extern const unsigned long sys_call_table[];
> >
> > */
> >
> > static inline int syscall_get_nr(struct task_struct *task, struct pt_regs
> >
> > *regs) {
> > - return regs->orig_ax & __SYSCALL_MASK;
> > + return regs->orig_ax;
> >
> > }
> >
> > static inline void syscall_rollback(struct task_struct *task,
> >
> > struct pt_regs *regs)
> >
> > {
> >
> > - regs->ax = regs->orig_ax & __SYSCALL_MASK;
> > + regs->ax = regs->orig_ax;
> >
> > }
> >
> > static inline long syscall_get_error(struct task_struct *task,
--
paul moore
security and virtualization @ redhat


2013-03-15 22:00:21

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [PATCH] x86: remove the x32 syscall bitmask from syscall_get_nr()

On 03/15/2013 02:15 PM, Paul Moore wrote:
> On Tuesday, February 26, 2013 03:58:23 PM Paul Moore wrote:
>> On Friday, February 15, 2013 12:21:43 PM Paul Moore wrote:
>>> Commit fca460f95e928bae373daa8295877b6905bc62b8 simplified the x32
>>> implementation by creating a syscall bitmask, equal to 0x40000000, that
>>> could be applied to x32 syscalls such that the masked syscall number
>>> would be the same as a x86_64 syscall. While that patch was a nice
>>> way to simplify the code, it went a bit too far by adding the mask to
>>> syscall_get_nr(); returning the masked syscall numbers can cause
>>> confusion with callers that expect syscall numbers matching the x32
>>> ABI, e.g. unmasked syscall numbers.
>>>
>>> This patch fixes this by simply removing the mask from syscall_get_nr()
>>> while preserving the other changes from the original commit. While
>>> there are several syscall_get_nr() callers in the kernel, most simply
>>> check that the syscall number is greater than zero, in this case this
>>> patch will have no effect. Of those remaining callers, they appear
>>> to be few, seccomp and ftrace, and from my testing of seccomp without
>>> this patch the original commit definitely breaks things; the seccomp
>>> filter does not correctly filter the syscalls due to the difference in
>>> syscall numbers in the BPF filter and the value from syscall_get_nr().
>>> Applying this patch restores the seccomp BPF filter functionality on
>>> x32.
>>>
>>> I've tested this patch with the seccomp BPF filters as well as ftrace
>>> and everything looks reasonable to me; needless to say general usage
>>> seemed fine as well.
>>
>> I just wanted to check and see where things stood with this patch. I'm not
>> overly concerned about how this problem is solved, just that it is solved.
>> If someone else has a better approach that is fine with me; I'll even make
>> the offer to do additional testing if needed.
>
> Anyone? The seccomp filter bits are completely broken on x32 and I'd like to
> get this fixed, if not with this patch then something else - I'm more than
> happy to test/verify/etc whatever solution is deemed best ...
>

Seems good to me -- H.J., do you seen any problem with this?

-hpa

>>> Signed-off-by: Paul Moore <[email protected]>
>>> Cc: [email protected]
>>> Cc: Will Drewry <[email protected]>
>>> Cc: H. Peter Anvin <[email protected]>
>>> ---
>>>
>>> arch/x86/include/asm/syscall.h | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/arch/x86/include/asm/syscall.h
>>> b/arch/x86/include/asm/syscall.h index 1ace47b..2e188d6 100644
>>> --- a/arch/x86/include/asm/syscall.h
>>> +++ b/arch/x86/include/asm/syscall.h
>>> @@ -29,13 +29,13 @@ extern const unsigned long sys_call_table[];
>>>
>>> */
>>>
>>> static inline int syscall_get_nr(struct task_struct *task, struct pt_regs
>>>
>>> *regs) {
>>> - return regs->orig_ax & __SYSCALL_MASK;
>>> + return regs->orig_ax;
>>>
>>> }
>>>
>>> static inline void syscall_rollback(struct task_struct *task,
>>>
>>> struct pt_regs *regs)
>>>
>>> {
>>>
>>> - regs->ax = regs->orig_ax & __SYSCALL_MASK;
>>> + regs->ax = regs->orig_ax;
>>>
>>> }
>>>
>>> static inline long syscall_get_error(struct task_struct *task,

2013-03-15 22:18:14

by H.J. Lu

[permalink] [raw]
Subject: Re: [PATCH] x86: remove the x32 syscall bitmask from syscall_get_nr()

On Fri, Mar 15, 2013 at 2:56 PM, H. Peter Anvin <[email protected]> wrote:
> On 03/15/2013 02:15 PM, Paul Moore wrote:
>> On Tuesday, February 26, 2013 03:58:23 PM Paul Moore wrote:
>>> On Friday, February 15, 2013 12:21:43 PM Paul Moore wrote:
>>>> Commit fca460f95e928bae373daa8295877b6905bc62b8 simplified the x32
>>>> implementation by creating a syscall bitmask, equal to 0x40000000, that
>>>> could be applied to x32 syscalls such that the masked syscall number
>>>> would be the same as a x86_64 syscall. While that patch was a nice
>>>> way to simplify the code, it went a bit too far by adding the mask to
>>>> syscall_get_nr(); returning the masked syscall numbers can cause
>>>> confusion with callers that expect syscall numbers matching the x32
>>>> ABI, e.g. unmasked syscall numbers.
>>>>
>>>> This patch fixes this by simply removing the mask from syscall_get_nr()
>>>> while preserving the other changes from the original commit. While
>>>> there are several syscall_get_nr() callers in the kernel, most simply
>>>> check that the syscall number is greater than zero, in this case this
>>>> patch will have no effect. Of those remaining callers, they appear
>>>> to be few, seccomp and ftrace, and from my testing of seccomp without
>>>> this patch the original commit definitely breaks things; the seccomp
>>>> filter does not correctly filter the syscalls due to the difference in
>>>> syscall numbers in the BPF filter and the value from syscall_get_nr().
>>>> Applying this patch restores the seccomp BPF filter functionality on
>>>> x32.
>>>>
>>>> I've tested this patch with the seccomp BPF filters as well as ftrace
>>>> and everything looks reasonable to me; needless to say general usage
>>>> seemed fine as well.
>>>
>>> I just wanted to check and see where things stood with this patch. I'm not
>>> overly concerned about how this problem is solved, just that it is solved.
>>> If someone else has a better approach that is fine with me; I'll even make
>>> the offer to do additional testing if needed.
>>
>> Anyone? The seccomp filter bits are completely broken on x32 and I'd like to
>> get this fixed, if not with this patch then something else - I'm more than
>> happy to test/verify/etc whatever solution is deemed best ...
>>
>
> Seems good to me -- H.J., do you seen any problem with this?
>

It looks OK to me.

--
H.J.

2013-03-25 20:55:49

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH] x86: remove the x32 syscall bitmask from syscall_get_nr()

On Friday, March 15, 2013 03:18:12 PM H.J. Lu wrote:
> On Fri, Mar 15, 2013 at 2:56 PM, H. Peter Anvin <[email protected]> wrote:
> > On 03/15/2013 02:15 PM, Paul Moore wrote:
> >> On Tuesday, February 26, 2013 03:58:23 PM Paul Moore wrote:
> >>> On Friday, February 15, 2013 12:21:43 PM Paul Moore wrote:
> >>>> Commit fca460f95e928bae373daa8295877b6905bc62b8 simplified the x32
> >>>> implementation by creating a syscall bitmask, equal to 0x40000000, that
> >>>> could be applied to x32 syscalls such that the masked syscall number
> >>>> would be the same as a x86_64 syscall. While that patch was a nice
> >>>> way to simplify the code, it went a bit too far by adding the mask to
> >>>> syscall_get_nr(); returning the masked syscall numbers can cause
> >>>> confusion with callers that expect syscall numbers matching the x32
> >>>> ABI, e.g. unmasked syscall numbers.
> >>>>
> >>>> This patch fixes this by simply removing the mask from syscall_get_nr()
> >>>> while preserving the other changes from the original commit. While
> >>>> there are several syscall_get_nr() callers in the kernel, most simply
> >>>> check that the syscall number is greater than zero, in this case this
> >>>> patch will have no effect. Of those remaining callers, they appear
> >>>> to be few, seccomp and ftrace, and from my testing of seccomp without
> >>>> this patch the original commit definitely breaks things; the seccomp
> >>>> filter does not correctly filter the syscalls due to the difference in
> >>>> syscall numbers in the BPF filter and the value from syscall_get_nr().
> >>>> Applying this patch restores the seccomp BPF filter functionality on
> >>>> x32.
> >>>>
> >>>> I've tested this patch with the seccomp BPF filters as well as ftrace
> >>>> and everything looks reasonable to me; needless to say general usage
> >>>> seemed fine as well.
> >>>
> >>> I just wanted to check and see where things stood with this patch. I'm
> >>> not
> >>> overly concerned about how this problem is solved, just that it is
> >>> solved.
> >>> If someone else has a better approach that is fine with me; I'll even
> >>> make
> >>> the offer to do additional testing if needed.
> >>
> >> Anyone? The seccomp filter bits are completely broken on x32 and I'd
> >> like to get this fixed, if not with this patch then something else - I'm
> >> more than happy to test/verify/etc whatever solution is deemed best ...
> >
> > Seems good to me -- H.J., do you seen any problem with this?
>
> It looks OK to me.

Great, any chance of getting this fix merged for 3.9?

--
paul moore
security and virtualization @ redhat

2013-04-02 21:34:19

by Paul Moore

[permalink] [raw]
Subject: Re: [PATCH] x86: remove the x32 syscall bitmask from syscall_get_nr()

On Monday, March 25, 2013 04:55:17 PM Paul Moore wrote:
> On Friday, March 15, 2013 03:18:12 PM H.J. Lu wrote:
> > On Fri, Mar 15, 2013 at 2:56 PM, H. Peter Anvin <[email protected]> wrote:
> > > On 03/15/2013 02:15 PM, Paul Moore wrote:
> > >> On Tuesday, February 26, 2013 03:58:23 PM Paul Moore wrote:
> > >>> On Friday, February 15, 2013 12:21:43 PM Paul Moore wrote:
> > >>>> Commit fca460f95e928bae373daa8295877b6905bc62b8 simplified the x32
> > >>>> implementation by creating a syscall bitmask, equal to 0x40000000,
> > >>>> that
> > >>>> could be applied to x32 syscalls such that the masked syscall number
> > >>>> would be the same as a x86_64 syscall. While that patch was a nice
> > >>>> way to simplify the code, it went a bit too far by adding the mask to
> > >>>> syscall_get_nr(); returning the masked syscall numbers can cause
> > >>>> confusion with callers that expect syscall numbers matching the x32
> > >>>> ABI, e.g. unmasked syscall numbers.
> > >>>>
> > >>>> This patch fixes this by simply removing the mask from
> > >>>> syscall_get_nr()
> > >>>> while preserving the other changes from the original commit. While
> > >>>> there are several syscall_get_nr() callers in the kernel, most simply
> > >>>> check that the syscall number is greater than zero, in this case this
> > >>>> patch will have no effect. Of those remaining callers, they appear
> > >>>> to be few, seccomp and ftrace, and from my testing of seccomp without
> > >>>> this patch the original commit definitely breaks things; the seccomp
> > >>>> filter does not correctly filter the syscalls due to the difference
> > >>>> in
> > >>>> syscall numbers in the BPF filter and the value from
> > >>>> syscall_get_nr().
> > >>>> Applying this patch restores the seccomp BPF filter functionality on
> > >>>> x32.
> > >>>>
> > >>>> I've tested this patch with the seccomp BPF filters as well as ftrace
> > >>>> and everything looks reasonable to me; needless to say general usage
> > >>>> seemed fine as well.
> > >>>
> > >>> I just wanted to check and see where things stood with this patch.
> > >>> I'm
> > >>> not
> > >>> overly concerned about how this problem is solved, just that it is
> > >>> solved.
> > >>> If someone else has a better approach that is fine with me; I'll even
> > >>> make
> > >>> the offer to do additional testing if needed.
> > >>
> > >> Anyone? The seccomp filter bits are completely broken on x32 and I'd
> > >> like to get this fixed, if not with this patch then something else -
> > >> I'm
> > >> more than happy to test/verify/etc whatever solution is deemed best ...
> > >
> > > Seems good to me -- H.J., do you seen any problem with this?
> >
> > It looks OK to me.
>
> Great, any chance of getting this fix merged for 3.9?

Just a ping to see where we stand on getting this patch merged. Just a
reminder that SECCOMP_FILTER is completely broken on x32 and either needs this
patch, or another one, to fix the regression.

--
paul moore
security and virtualization @ redhat