[RFC PATCH 1/4] net: introduce get_optlen() and put_optlen() helpers
Stefan Metzmacher
metze at samba.org
Tue Apr 1 05:22:50 PDT 2025
Hello Breno,
> On Mon, Mar 31, 2025 at 10:10:53PM +0200, Stefan Metzmacher wrote:
>> --- a/include/linux/sockptr.h
>> +++ b/include/linux/sockptr.h
>> @@ -169,4 +169,26 @@ static inline int check_zeroed_sockptr(sockptr_t src, size_t offset,
>> return memchr_inv(src.kernel + offset, 0, size) == NULL;
>> }
>>
>> +#define __check_optlen_t(__optlen) \
>> +({ \
>> + int __user *__ptr __maybe_unused = __optlen; \
>> + BUILD_BUG_ON(sizeof(*(__ptr)) != sizeof(int)); \
>> +})
>
> I am a bit confused about this macro. I understand that this macro's
> goal is to check that __optlen is a pointer to an integer, otherwise
> failed to build.
>
> It is unclear to me if that is what it does. Let's suppose that __optlen
> is not an integer pointer. Then:
>
>> int __user *__ptr __maybe_unused = __optlen;
>
> This will generate a compile failure/warning due invalid casting,
> depending on -Wincompatible-pointer-types.
>
>> BUILD_BUG_ON(sizeof(*(__ptr)) != sizeof(int));
>
> Then this comparison will always false, since __ptr is a pointer to int,
> and you are comparing the size of its content with the sizeof(int).
Yes, it redundant in the first patch, it gets little more useful in
the 2nd and 3rd patch.
metze
More information about the linux-afs
mailing list