Linux-MIPS Archive mirror
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: kernel test robot <lkp@intel.com>, linux-mips@vger.kernel.org
Cc: oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org,
	 Thomas Gleixner <tglx@kernel.org>
Subject: Re: include/vdso/unaligned.h:23:9: warning: '__builtin_memcpy' reading 4 bytes from a region of size 0
Date: Mon, 6 Apr 2026 22:12:41 -0700	[thread overview]
Message-ID: <CAP-5=fVBZPBz6J1omfvSS4JLkueRGqCdouLji6gsFLTeu9nJTw@mail.gmail.com> (raw)
In-Reply-To: <202604070917.ZVd6Ugz4-lkp@intel.com>

On Mon, Apr 6, 2026 at 9:03 PM kernel test robot <lkp@intel.com> wrote:
>
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head:   bfe62a454542cfad3379f6ef5680b125f41e20f4
> commit: a339671db64b12bb02492557d2b0658811286277 vdso: Switch get/put_unaligned() from packed struct to memcpy()
> date:   3 months ago
> config: mips-randconfig-r111-20260406 (https://download.01.org/0day-ci/archive/20260407/202604070917.ZVd6Ugz4-lkp@intel.com/config)
> compiler: mips-linux-gcc (GCC) 13.4.0
> sparse: v0.6.5-rc1
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260407/202604070917.ZVd6Ugz4-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Fixes: a339671db64b ("vdso: Switch get/put_unaligned() from packed struct to memcpy()")
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202604070917.ZVd6Ugz4-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
>    In file included from include/linux/byteorder/little_endian.h:5,
>                     from arch/mips/include/uapi/asm/byteorder.h:15,
>                     from arch/mips/include/asm/bitops.h:21,
>                     from include/linux/bitops.h:67,
>                     from include/linux/kernel.h:23,
>                     from arch/mips/boot/compressed/decompress.c:14:
>    In function 'get_unaligned_le32',
>        inlined from 'decompress_kernel' at arch/mips/boot/compressed/decompress.c:113:16:
> >> include/vdso/unaligned.h:23:9: warning: '__builtin_memcpy' reading 4 bytes from a region of size 0 [-Wstringop-overread]
>       23 |         __builtin_memcpy(&__get_unaligned_val, (void *)(ptr),           \
>          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>       24 |                          sizeof(__get_unaligned_val));                  \
>          |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    include/uapi/linux/byteorder/little_endian.h:35:51: note: in definition of macro '__le32_to_cpu'
>       35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
>          |                                                   ^
>    include/linux/unaligned.h:23:28: note: in expansion of macro '__get_unaligned_t'
>       23 |         return le32_to_cpu(__get_unaligned_t(__le32, p));
>          |                            ^~~~~~~~~~~~~~~~~
>    In file included from arch/mips/boot/compressed/decompress.c:22:
>    arch/mips/boot/compressed/decompress.h: In function 'decompress_kernel':
>    arch/mips/boot/compressed/decompress.h:6:39: note: at offset -4 into source object '__image_end' of size [0, 2147483647]
>        6 | extern unsigned char __image_begin[], __image_end[];
>          |                                       ^~~~~~~~~~~

I wonder if in:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/mips/boot/compressed/decompress.c#n113
```
image_size = get_unaligned_le32((void *)__image_end - 4);
```
would be better as:
```
image_size = get_unaligned_le32((void *)__image_begin + zimage_size - 4);
```
so that the code isn't negatively indexing an array.

Thanks,
Ian

>
> vim +/__builtin_memcpy +23 include/vdso/unaligned.h
>
>      6
>      7  /**
>      8   * __get_unaligned_t - read an unaligned value from memory.
>      9   * @type:       the type to load from the pointer.
>     10   * @ptr:        the pointer to load from.
>     11   *
>     12   * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
>     13   * from approaches like type punning that require -fno-strict-aliasing in order
>     14   * to be correct. As type may be const, use __unqual_scalar_typeof to map to a
>     15   * non-const type - you can't memcpy into a const type. The
>     16   * __get_unaligned_ctrl_type gives __unqual_scalar_typeof its required
>     17   * expression rather than type, a pointer is used to avoid warnings about mixing
>     18   * the use of 0 and NULL. The void* cast silences ubsan warnings.
>     19   */
>     20  #define __get_unaligned_t(type, ptr) ({                                 \
>     21          type *__get_unaligned_ctrl_type __always_unused = NULL;         \
>     22          __unqual_scalar_typeof(*__get_unaligned_ctrl_type) __get_unaligned_val; \
>   > 23          __builtin_memcpy(&__get_unaligned_val, (void *)(ptr),           \
>     24                           sizeof(__get_unaligned_val));                  \
>     25          __get_unaligned_val;                                            \
>     26  })
>     27
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

           reply	other threads:[~2026-04-07  5:12 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <202604070917.ZVd6Ugz4-lkp@intel.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAP-5=fVBZPBz6J1omfvSS4JLkueRGqCdouLji6gsFLTeu9nJTw@mail.gmail.com' \
    --to=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=tglx@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).