2022-02-14 09:28:53

by David Laight

[permalink] [raw]
Subject: RE: [PATCH] fat: Use pointer to d_name[0] in put_user() for compat case

From: Helge Deller
> Sent: 13 February 2022 22:10
>
> The put_user(val,ptr) macro wants a pointer in the second parameter, but in
> fat_ioctl_filldir() the d_name field references a whole "array of chars".
> Usually the compiler automatically converts it and uses a pointer to that
> array, but it's more clean to explicitly give the real pointer to where someting
> is put, which is in this case the first character of the d_name[] array.

That just isn't true.

In C both x->char_array and &x->char_array[0] have the same type
'char *'.

The 'bug' is caused by put_user() trying to do:
__typeof__(ptr) __ptr = ptr;
where __typeof__ is returning char[n] not char *.

I've tried a few things but can't get __typeof__ to
generate a suitable type for both a simple type and array.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


2022-02-14 18:48:12

by David Laight

[permalink] [raw]
Subject: RE: [PATCH] fat: Use pointer to d_name[0] in put_user() for compat case

From: David Laight
> Sent: 14 February 2022 09:12
>
> From: Helge Deller
> > Sent: 13 February 2022 22:10
> >
> > The put_user(val,ptr) macro wants a pointer in the second parameter, but in
> > fat_ioctl_filldir() the d_name field references a whole "array of chars".
> > Usually the compiler automatically converts it and uses a pointer to that
> > array, but it's more clean to explicitly give the real pointer to where someting
> > is put, which is in this case the first character of the d_name[] array.
>
> That just isn't true.
>
> In C both x->char_array and &x->char_array[0] have the same type
> 'char *'.
>
> The 'bug' is caused by put_user() trying to do:
> __typeof__(ptr) __ptr = ptr;
> where __typeof__ is returning char[n] not char *.
>
> I've tried a few things but can't get __typeof__ to
> generate a suitable type for both a simple type and array.

Actually the issue is that put_user() writes a single variable
and needs a pointer to one.
So changing to:
put_user(0, &array[0]);
is probably fine.
But the description is all wrong.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

2022-02-14 19:16:42

by Helge Deller

[permalink] [raw]
Subject: Re: [PATCH] fat: Use pointer to d_name[0] in put_user() for compat case

On 2/14/22 10:26, David Laight wrote:
> From: David Laight
>> Sent: 14 February 2022 09:12
>>
>> From: Helge Deller
>>> Sent: 13 February 2022 22:10
>>>
>>> The put_user(val,ptr) macro wants a pointer in the second parameter, but in
>>> fat_ioctl_filldir() the d_name field references a whole "array of chars".
>>> Usually the compiler automatically converts it and uses a pointer to that
>>> array, but it's more clean to explicitly give the real pointer to where someting
>>> is put, which is in this case the first character of the d_name[] array.
>>
>> That just isn't true.
>>
>> In C both x->char_array and &x->char_array[0] have the same type
>> 'char *'.
>>
>> The 'bug' is caused by put_user() trying to do:
>> __typeof__(ptr) __ptr = ptr;
>> where __typeof__ is returning char[n] not char *.
>>
>> I've tried a few things but can't get __typeof__ to
>> generate a suitable type for both a simple type and array.
>
> Actually the issue is that put_user() writes a single variable
> and needs a pointer to one.
> So changing to:
> put_user(0, &array[0]);
> is probably fine.

Ok.

> But the description is all wrong.

I agree it can be improved.
Would you mind proposing a better description?

Helge

2022-02-14 21:15:05

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH] fat: Use pointer to d_name[0] in put_user() for compat case

On Feb 14 2022, David Laight wrote:

> The 'bug' is caused by put_user() trying to do:
> __typeof__(ptr) __ptr = ptr;
> where __typeof__ is returning char[n] not char *.
>
> I've tried a few things but can't get __typeof__ to
> generate a suitable type for both a simple type and array.

Does it work to use __typeof__(&*(ptr))?

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."