Re: [RFC PATCH 1/4] net: introduce get_optlen() and put_optlen() helpers
From: Breno Leitao
Date: Tue Apr 01 2025 - 08:17:49 EST
Hello Stefan,
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).