lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202411091357.6tKo6nby-lkp@intel.com>
Date: Sat, 9 Nov 2024 14:06:13 +0800
From: kernel test robot <lkp@...el.com>
To: Jacob Keller <jacob.e.keller@...el.com>,
	Vladimir Oltean <olteanv@...il.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	Tony Nguyen <anthony.l.nguyen@...el.com>,
	Przemek Kitszel <przemyslaw.kitszel@...el.com>,
	Masahiro Yamada <masahiroy@...nel.org>,
	netdev <netdev@...r.kernel.org>
Cc: oe-kbuild-all@...ts.linux.dev,
	Linux Memory Management List <linux-mm@...ck.org>,
	linux-kbuild@...r.kernel.org,
	Jacob Keller <jacob.e.keller@...el.com>
Subject: Re: [PATCH net-next v4 3/9] lib: packing: add pack_fields() and
 unpack_fields()

Hi Jacob,

kernel test robot noticed the following build warnings:

[auto build test WARNING on a84e8c05f58305dfa808bc5465c5175c29d7c9b6]

url:    https://github.com/intel-lab-lkp/linux/commits/Jacob-Keller/lib-packing-create-__pack-and-__unpack-variants-without-error-checking/20241109-093307
base:   a84e8c05f58305dfa808bc5465c5175c29d7c9b6
patch link:    https://lore.kernel.org/r/20241108-packing-pack-fields-and-ice-implementation-v4-3-81a9f42c30e5%40intel.com
patch subject: [PATCH net-next v4 3/9] lib: packing: add pack_fields() and unpack_fields()
config: openrisc-allnoconfig (https://download.01.org/0day-ci/archive/20241109/202411091357.6tKo6nby-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241109/202411091357.6tKo6nby-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
| Reported-by: kernel test robot <lkp@...el.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411091357.6tKo6nby-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from scripts/mod/packed_fields.c:15:
   scripts/mod/packed_fields.c: In function 'handle_packed_field_symbol':
>> scripts/mod/packed_fields.c:134:23: warning: format '%zu' expects argument of type 'size_t', but argument 5 has type 'Elf32_Word' {aka 'unsigned int'} [-Wformat=]
     134 |                 error("[%s.ko] \"%s\" has size %zu which is not a multiple of the field size (%zu)\n",
         |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     135 |                       mod->name, symname, sym->st_size, field_size);
         |                                           ~~~~~~~~~~~~
         |                                              |
         |                                              Elf32_Word {aka unsigned int}
   scripts/mod/modpost.h:207:51: note: in definition of macro 'error'
     207 | #define error(fmt, args...)     modpost_log(true, fmt, ##args)
         |                                                   ^~~
   scripts/mod/packed_fields.c:134:50: note: format string is defined here
     134 |                 error("[%s.ko] \"%s\" has size %zu which is not a multiple of the field size (%zu)\n",
         |                                                ~~^
         |                                                  |
         |                                                  long unsigned int
         |                                                %u
--
   In file included from scripts/mod/packed_fields.c:15:
   scripts/mod/packed_fields.c: In function 'handle_packed_field_symbol':
>> scripts/mod/packed_fields.c:134:23: warning: format '%zu' expects argument of type 'size_t', but argument 5 has type 'Elf32_Word' {aka 'unsigned int'} [-Wformat=]
     134 |                 error("[%s.ko] \"%s\" has size %zu which is not a multiple of the field size (%zu)\n",
         |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     135 |                       mod->name, symname, sym->st_size, field_size);
         |                                           ~~~~~~~~~~~~
         |                                              |
         |                                              Elf32_Word {aka unsigned int}
   scripts/mod/modpost.h:207:51: note: in definition of macro 'error'
     207 | #define error(fmt, args...)     modpost_log(true, fmt, ##args)
         |                                                   ^~~
   scripts/mod/packed_fields.c:134:50: note: format string is defined here
     134 |                 error("[%s.ko] \"%s\" has size %zu which is not a multiple of the field size (%zu)\n",
         |                                                ~~^
         |                                                  |
         |                                                  long unsigned int
         |                                                %u


vim +134 scripts/mod/packed_fields.c

    14	
  > 15	#include "modpost.h"
    16	
    17	typedef uint16_t	u16;
    18	typedef uint8_t		u8;
    19	
    20	#define BITS_PER_BYTE	8
    21	
    22	/* Big exception to the "don't include kernel headers into userspace", which
    23	 * even potentially has different endianness and word sizes, since we handle
    24	 * those differences explicitly below
    25	 */
    26	#include "../../include/linux/packing_types.h"
    27	
    28	#define max(a, b) ({\
    29			typeof(a) _a = a;\
    30			typeof(b) _b = b;\
    31			_a > _b ? _a : _b; })
    32	
    33	#define min(a, b) ({\
    34			typeof(a) _a = a;\
    35			typeof(b) _b = b;\
    36			_a < _b ? _a : _b; })
    37	
    38	struct packed_field_elem {
    39		uint64_t startbit;
    40		uint64_t endbit;
    41		uint64_t offset;
    42		uint64_t size;
    43	};
    44	
    45	enum field_type {
    46		UNKNOWN_SECTION,
    47		PACKED_FIELD_S,
    48		PACKED_FIELD_M,
    49	};
    50	
    51	enum element_order {
    52		FIRST_ELEMENT,
    53		SECOND_ELEMENT,
    54		ASCENDING_ORDER,
    55		DESCENDING_ORDER,
    56	};
    57	
    58	static size_t field_type_to_size(enum field_type type)
    59	{
    60		switch (type) {
    61		case PACKED_FIELD_S:
    62			return sizeof(struct packed_field_s);
    63		case PACKED_FIELD_M:
    64			return sizeof(struct packed_field_m);
    65		default:
    66			error("attempted to get field size for unknown packed field type %u\n",
    67			      type);
    68			return 0;
    69		}
    70	}
    71	
    72	static void get_field_contents(const void *data, enum field_type type,
    73				       struct packed_field_elem *elem)
    74	{
    75		switch (type) {
    76		case PACKED_FIELD_S: {
    77			const struct packed_field_s *data_field = data;
    78	
    79			elem->startbit = TO_NATIVE(data_field->startbit);
    80			elem->endbit = TO_NATIVE(data_field->endbit);
    81			elem->offset = TO_NATIVE(data_field->offset);
    82			elem->size = TO_NATIVE(data_field->size);
    83			return;
    84		}
    85		case PACKED_FIELD_M: {
    86			const struct packed_field_m *data_field = data;
    87	
    88			elem->startbit = TO_NATIVE(data_field->startbit);
    89			elem->endbit = TO_NATIVE(data_field->endbit);
    90			elem->offset = TO_NATIVE(data_field->offset);
    91			elem->size = TO_NATIVE(data_field->size);
    92			return;
    93		}
    94		default:
    95			error("attempted to get field contents for unknown packed field type %u\n",
    96			      type);
    97		}
    98	}
    99	
   100	void handle_packed_field_symbol(struct module *mod, struct elf_info *info,
   101					Elf_Sym *sym, const char *symname)
   102	{
   103		unsigned int secindex = get_secindex(info, sym);
   104		struct packed_field_elem elem = {}, prev = {};
   105		enum element_order order = FIRST_ELEMENT;
   106		enum field_type type = UNKNOWN_SECTION;
   107		size_t field_size, count;
   108		const void *data, *ptr;
   109		const char *section;
   110	
   111		/* Skip symbols without a name */
   112		if (*symname == '\0')
   113			return;
   114	
   115		/* Skip symbols with invalid sections */
   116		if (secindex >= info->num_sections)
   117			return;
   118	
   119		section = sec_name(info, secindex);
   120	
   121		if (strcmp(section, ".rodata.packed_fields_s") == 0)
   122			type = PACKED_FIELD_S;
   123		else if (strcmp(section, ".rodata.packed_fields_m") == 0)
   124			type = PACKED_FIELD_M;
   125	
   126		/* Other sections don't relate to packed fields */
   127		if (type == UNKNOWN_SECTION)
   128			return;
   129	
   130		field_size = field_type_to_size(type);
   131	
   132		/* check that the data is a multiple of the size */
   133		if (sym->st_size % field_size != 0) {
 > 134			error("[%s.ko] \"%s\" has size %zu which is not a multiple of the field size (%zu)\n",

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ