2020-03-04 06:41:24

by He Zhe

[permalink] [raw]
Subject: [PATCH] x86/mce: Add compat_ioctl assignment to make it compatible with 32-bit system

From: He Zhe <[email protected]>

32-bit user-space program would get errors like the following from ioctl
syscall due to missing compat_ioctl.
MCE_GET_RECORD_LEN: Inappropriate ioctl for device

compat_ptr_ioctl is provided as a generic implementation of .compat_ioctl
file operation to ioctl functions that either ignore the argument or pass
a pointer to a compatible data type.

Signed-off-by: He Zhe <[email protected]>
---
arch/x86/kernel/cpu/mce/dev-mcelog.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
index 7c8958d..6c9b91b7 100644
--- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
+++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
@@ -328,6 +328,7 @@ static const struct file_operations mce_chrdev_ops = {
.write = mce_chrdev_write,
.poll = mce_chrdev_poll,
.unlocked_ioctl = mce_chrdev_ioctl,
+ .compat_ioctl = compat_ptr_ioctl,
.llseek = no_llseek,
};

--
2.7.4


2020-04-16 08:48:25

by He Zhe

[permalink] [raw]
Subject: Re: [PATCH] x86/mce: Add compat_ioctl assignment to make it compatible with 32-bit system

Can this be considered for the moment?

Thanks,
Zhe

On 3/4/20 2:39 PM, [email protected] wrote:
> From: He Zhe <[email protected]>
>
> 32-bit user-space program would get errors like the following from ioctl
> syscall due to missing compat_ioctl.
> MCE_GET_RECORD_LEN: Inappropriate ioctl for device
>
> compat_ptr_ioctl is provided as a generic implementation of .compat_ioctl
> file operation to ioctl functions that either ignore the argument or pass
> a pointer to a compatible data type.
>
> Signed-off-by: He Zhe <[email protected]>
> ---
> arch/x86/kernel/cpu/mce/dev-mcelog.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
> index 7c8958d..6c9b91b7 100644
> --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
> +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
> @@ -328,6 +328,7 @@ static const struct file_operations mce_chrdev_ops = {
> .write = mce_chrdev_write,
> .poll = mce_chrdev_poll,
> .unlocked_ioctl = mce_chrdev_ioctl,
> + .compat_ioctl = compat_ptr_ioctl,
> .llseek = no_llseek,
> };
>

2020-04-27 18:20:55

by Luck, Tony

[permalink] [raw]
Subject: Re: [PATCH] x86/mce: Add compat_ioctl assignment to make it compatible with 32-bit system

On Thu, Apr 16, 2020 at 04:40:31PM +0800, He Zhe wrote:
> Can this be considered for the moment?
>
> Thanks,
> Zhe
>
> On 3/4/20 2:39 PM, [email protected] wrote:
> > From: He Zhe <[email protected]>
> >
> > 32-bit user-space program would get errors like the following from ioctl
> > syscall due to missing compat_ioctl.
> > MCE_GET_RECORD_LEN: Inappropriate ioctl for device
> >
> > compat_ptr_ioctl is provided as a generic implementation of .compat_ioctl
> > file operation to ioctl functions that either ignore the argument or pass
> > a pointer to a compatible data type.

I'm not super-familiar with the compat ioctl bits. But this looks plausible.

All three of the ioctl's for this driver have a "pointer to integer" for the
"return" value. And "int" is a compatible type between i386 and x86_64.

I don't have a system setup to build a 32-bit binary to test the theory,
but I assume that you have built something that tests all three:

MCE_GET_RECORD_LEN
MCE_GET_LOG_LEN
MCE_GETCLEAR_FLAGS

So I guess:

Acked-by: Tony Luck <[email protected]>

> >
> > Signed-off-by: He Zhe <[email protected]>
> > ---
> > arch/x86/kernel/cpu/mce/dev-mcelog.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
> > index 7c8958d..6c9b91b7 100644
> > --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
> > +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
> > @@ -328,6 +328,7 @@ static const struct file_operations mce_chrdev_ops = {
> > .write = mce_chrdev_write,
> > .poll = mce_chrdev_poll,
> > .unlocked_ioctl = mce_chrdev_ioctl,
> > + .compat_ioctl = compat_ptr_ioctl,
> > .llseek = no_llseek,
> > };
> >
>

2020-05-02 14:23:45

by He Zhe

[permalink] [raw]
Subject: Re: [PATCH] x86/mce: Add compat_ioctl assignment to make it compatible with 32-bit system



On 4/28/20 2:19 AM, Luck, Tony wrote:
> On Thu, Apr 16, 2020 at 04:40:31PM +0800, He Zhe wrote:
>> Can this be considered for the moment?
>>
>> Thanks,
>> Zhe
>>
>> On 3/4/20 2:39 PM, [email protected] wrote:
>>> From: He Zhe <[email protected]>
>>>
>>> 32-bit user-space program would get errors like the following from ioctl
>>> syscall due to missing compat_ioctl.
>>> MCE_GET_RECORD_LEN: Inappropriate ioctl for device
>>>
>>> compat_ptr_ioctl is provided as a generic implementation of .compat_ioctl
>>> file operation to ioctl functions that either ignore the argument or pass
>>> a pointer to a compatible data type.
> I'm not super-familiar with the compat ioctl bits. But this looks plausible.
>
> All three of the ioctl's for this driver have a "pointer to integer" for the
> "return" value. And "int" is a compatible type between i386 and x86_64.
>
> I don't have a system setup to build a 32-bit binary to test the theory,
> but I assume that you have built something that tests all three:
>
> MCE_GET_RECORD_LEN
> MCE_GET_LOG_LEN
> MCE_GETCLEAR_FLAGS
>
> So I guess:
>
> Acked-by: Tony Luck <[email protected]>

Thanks, and yes, I had tested all three.

Zhe

>
>>> Signed-off-by: He Zhe <[email protected]>
>>> ---
>>> arch/x86/kernel/cpu/mce/dev-mcelog.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
>>> index 7c8958d..6c9b91b7 100644
>>> --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
>>> +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
>>> @@ -328,6 +328,7 @@ static const struct file_operations mce_chrdev_ops = {
>>> .write = mce_chrdev_write,
>>> .poll = mce_chrdev_poll,
>>> .unlocked_ioctl = mce_chrdev_ioctl,
>>> + .compat_ioctl = compat_ptr_ioctl,
>>> .llseek = no_llseek,
>>> };
>>>

Subject: [tip: ras/core] x86/mcelog: Add compat_ioctl for 32-bit mcelog support

The following commit has been merged into the ras/core branch of tip:

Commit-ID: 3b4ff4eb904fef04c36b39052ca8eb31fa41fad0
Gitweb: https://git.kernel.org/tip/3b4ff4eb904fef04c36b39052ca8eb31fa41fad0
Author: He Zhe <[email protected]>
AuthorDate: Wed, 04 Mar 2020 14:39:07 +08:00
Committer: Borislav Petkov <[email protected]>
CommitterDate: Mon, 04 May 2020 10:07:04 +02:00

x86/mcelog: Add compat_ioctl for 32-bit mcelog support

A 32-bit version of mcelog issuing ioctls on /dev/mcelog causes errors
like the following:

MCE_GET_RECORD_LEN: Inappropriate ioctl for device

This is due to a missing compat_ioctl callback.

Assign to it compat_ptr_ioctl() as a generic implementation of the
.compat_ioctl file operation to ioctl functions that either ignore the
argument or pass a pointer to a compatible data type.

[ bp: Massage commit message. ]

Signed-off-by: He Zhe <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Acked-by: Tony Luck <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
arch/x86/kernel/cpu/mce/dev-mcelog.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c
index c033e7e..a4fd528 100644
--- a/arch/x86/kernel/cpu/mce/dev-mcelog.c
+++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c
@@ -329,6 +329,7 @@ static const struct file_operations mce_chrdev_ops = {
.write = mce_chrdev_write,
.poll = mce_chrdev_poll,
.unlocked_ioctl = mce_chrdev_ioctl,
+ .compat_ioctl = compat_ptr_ioctl,
.llseek = no_llseek,
};