All of lore.kernel.org
 help / color / mirror / Atom feed
* [linux-next:master 7573/14131] include/linux/tpm_eventlog.h:198:20: warning: taking address of packed member 'count' of class or structure 'tcg_pcr_event2_head' may result in an unaligned pointer value
@ 2020-06-01 14:35 kbuild test robot
  0 siblings, 0 replies; only message in thread
From: kbuild test robot @ 2020-06-01 14:35 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 14024 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   e7b08814b16b80a0bf76eeca16317f8c2ed23b8c
commit: bbfa112b46bdbbdfc2f5bfb9c2dcbef780ff6417 [7573/14131] READ_ONCE: Simplify implementations of {READ,WRITE}_ONCE()
config: i386-randconfig-a013-20200601 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 2388a096e7865c043e83ece4e26654bd3d1a20d5)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install i386 cross compiling tool for clang build
        # apt-get install binutils-i386-linux-gnu
        git checkout bbfa112b46bdbbdfc2f5bfb9c2dcbef780ff6417
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>, old ones prefixed by <<):

clang-11: warning: optimization flag '-falign-jumps=0' is not supported [-Wignored-optimization-argument]
clang-11: warning: optimization flag '-falign-loops=0' is not supported [-Wignored-optimization-argument]
In file included from drivers/char/tpm/tpm-chip.c:18:
In file included from include/linux/poll.h:7:
In file included from include/linux/ktime.h:24:
In file included from include/linux/time.h:6:
In file included from include/linux/seqlock.h:36:
In file included from include/linux/spinlock.h:51:
In file included from include/linux/preempt.h:78:
In file included from arch/x86/include/asm/preempt.h:7:
In file included from include/linux/thread_info.h:38:
arch/x86/include/asm/thread_info.h:190:13: warning: calling '__builtin_frame_address' with a nonzero argument is unsafe [-Wframe-address]
oldframe = __builtin_frame_address(1);
^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/include/asm/thread_info.h:192:11: warning: calling '__builtin_frame_address' with a nonzero argument is unsafe [-Wframe-address]
frame = __builtin_frame_address(2);
^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from drivers/char/tpm/tpm-chip.c:24:
>> include/linux/tpm_eventlog.h:198:20: warning: taking address of packed member 'count' of class or structure 'tcg_pcr_event2_head' may result in an unaligned pointer value [-Waddress-of-packed-member]
count = READ_ONCE(event->count);
^~~~~~~~~~~~
include/linux/compiler.h:206:22: note: expanded from macro 'READ_ONCE'
typeof(x) *__xp = &(x);                                                                        ^
In file included from drivers/char/tpm/tpm-chip.c:24:
>> include/linux/tpm_eventlog.h:199:25: warning: taking address of packed member 'event_type' of class or structure 'tcg_pcr_event2_head' may result in an unaligned pointer value [-Waddress-of-packed-member]
event_type = READ_ONCE(event->event_type);
^~~~~~~~~~~~~~~~~
include/linux/compiler.h:206:22: note: expanded from macro 'READ_ONCE'
typeof(x) *__xp = &(x);                                                                        ^
4 warnings generated.

vim +198 include/linux/tpm_eventlog.h

c46f3405692de1 Matthew Garrett  2019-05-20  138  
44038bc514a244 Matthew Garrett  2019-05-20  139  /**
44038bc514a244 Matthew Garrett  2019-05-20  140   * __calc_tpm2_event_size - calculate the size of a TPM2 event log entry
44038bc514a244 Matthew Garrett  2019-05-20  141   * @event:        Pointer to the event whose size should be calculated
44038bc514a244 Matthew Garrett  2019-05-20  142   * @event_header: Pointer to the initial event containing the digest lengths
c46f3405692de1 Matthew Garrett  2019-05-20  143   * @do_mapping:   Whether or not the event needs to be mapped
44038bc514a244 Matthew Garrett  2019-05-20  144   *
44038bc514a244 Matthew Garrett  2019-05-20  145   * The TPM2 event log format can contain multiple digests corresponding to
44038bc514a244 Matthew Garrett  2019-05-20  146   * separate PCR banks, and also contains a variable length of the data that
44038bc514a244 Matthew Garrett  2019-05-20  147   * was measured. This requires knowledge of how long each digest type is,
44038bc514a244 Matthew Garrett  2019-05-20  148   * and this information is contained within the first event in the log.
44038bc514a244 Matthew Garrett  2019-05-20  149   *
44038bc514a244 Matthew Garrett  2019-05-20  150   * We calculate the length by examining the number of events, and then looking
44038bc514a244 Matthew Garrett  2019-05-20  151   * at each event in turn to determine how much space is used for events in
44038bc514a244 Matthew Garrett  2019-05-20  152   * total. Once we've done this we know the offset of the data length field,
44038bc514a244 Matthew Garrett  2019-05-20  153   * and can calculate the total size of the event.
44038bc514a244 Matthew Garrett  2019-05-20  154   *
e658c82be55614 Jerry Snitselaar 2019-10-02  155   * Return: size of the event on success, 0 on failure
44038bc514a244 Matthew Garrett  2019-05-20  156   */
44038bc514a244 Matthew Garrett  2019-05-20  157  
44038bc514a244 Matthew Garrett  2019-05-20  158  static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
c46f3405692de1 Matthew Garrett  2019-05-20  159  					 struct tcg_pcr_event *event_header,
c46f3405692de1 Matthew Garrett  2019-05-20  160  					 bool do_mapping)
44038bc514a244 Matthew Garrett  2019-05-20  161  {
44038bc514a244 Matthew Garrett  2019-05-20  162  	struct tcg_efi_specid_event_head *efispecid;
44038bc514a244 Matthew Garrett  2019-05-20  163  	struct tcg_event_field *event_field;
c46f3405692de1 Matthew Garrett  2019-05-20  164  	void *mapping = NULL;
c46f3405692de1 Matthew Garrett  2019-05-20  165  	int mapping_size;
44038bc514a244 Matthew Garrett  2019-05-20  166  	void *marker;
44038bc514a244 Matthew Garrett  2019-05-20  167  	void *marker_start;
44038bc514a244 Matthew Garrett  2019-05-20  168  	u32 halg_size;
44038bc514a244 Matthew Garrett  2019-05-20  169  	size_t size;
44038bc514a244 Matthew Garrett  2019-05-20  170  	u16 halg;
44038bc514a244 Matthew Garrett  2019-05-20  171  	int i;
44038bc514a244 Matthew Garrett  2019-05-20  172  	int j;
047d50aee341d9 Peter Jones      2019-10-02  173  	u32 count, event_type;
44038bc514a244 Matthew Garrett  2019-05-20  174  
44038bc514a244 Matthew Garrett  2019-05-20  175  	marker = event;
44038bc514a244 Matthew Garrett  2019-05-20  176  	marker_start = marker;
44038bc514a244 Matthew Garrett  2019-05-20  177  	marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type)
44038bc514a244 Matthew Garrett  2019-05-20  178  		+ sizeof(event->count);
44038bc514a244 Matthew Garrett  2019-05-20  179  
c46f3405692de1 Matthew Garrett  2019-05-20  180  	/* Map the event header */
c46f3405692de1 Matthew Garrett  2019-05-20  181  	if (do_mapping) {
c46f3405692de1 Matthew Garrett  2019-05-20  182  		mapping_size = marker - marker_start;
c46f3405692de1 Matthew Garrett  2019-05-20  183  		mapping = TPM_MEMREMAP((unsigned long)marker_start,
c46f3405692de1 Matthew Garrett  2019-05-20  184  				       mapping_size);
c46f3405692de1 Matthew Garrett  2019-05-20  185  		if (!mapping) {
c46f3405692de1 Matthew Garrett  2019-05-20  186  			size = 0;
c46f3405692de1 Matthew Garrett  2019-05-20  187  			goto out;
c46f3405692de1 Matthew Garrett  2019-05-20  188  		}
c46f3405692de1 Matthew Garrett  2019-05-20  189  	} else {
c46f3405692de1 Matthew Garrett  2019-05-20  190  		mapping = marker_start;
c46f3405692de1 Matthew Garrett  2019-05-20  191  	}
c46f3405692de1 Matthew Garrett  2019-05-20  192  
c46f3405692de1 Matthew Garrett  2019-05-20  193  	event = (struct tcg_pcr_event2_head *)mapping;
047d50aee341d9 Peter Jones      2019-10-02  194  	/*
047d50aee341d9 Peter Jones      2019-10-02  195  	 * The loop below will unmap these fields if the log is larger than
047d50aee341d9 Peter Jones      2019-10-02  196  	 * one page, so save them here for reference:
047d50aee341d9 Peter Jones      2019-10-02  197  	 */
047d50aee341d9 Peter Jones      2019-10-02 @198  	count = READ_ONCE(event->count);
047d50aee341d9 Peter Jones      2019-10-02 @199  	event_type = READ_ONCE(event->event_type);
c46f3405692de1 Matthew Garrett  2019-05-20  200  
44038bc514a244 Matthew Garrett  2019-05-20  201  	efispecid = (struct tcg_efi_specid_event_head *)event_header->event;
44038bc514a244 Matthew Garrett  2019-05-20  202  
44038bc514a244 Matthew Garrett  2019-05-20  203  	/* Check if event is malformed. */
047d50aee341d9 Peter Jones      2019-10-02  204  	if (count > efispecid->num_algs) {
c46f3405692de1 Matthew Garrett  2019-05-20  205  		size = 0;
c46f3405692de1 Matthew Garrett  2019-05-20  206  		goto out;
c46f3405692de1 Matthew Garrett  2019-05-20  207  	}
44038bc514a244 Matthew Garrett  2019-05-20  208  
047d50aee341d9 Peter Jones      2019-10-02  209  	for (i = 0; i < count; i++) {
44038bc514a244 Matthew Garrett  2019-05-20  210  		halg_size = sizeof(event->digests[i].alg_id);
c46f3405692de1 Matthew Garrett  2019-05-20  211  
c46f3405692de1 Matthew Garrett  2019-05-20  212  		/* Map the digest's algorithm identifier */
c46f3405692de1 Matthew Garrett  2019-05-20  213  		if (do_mapping) {
c46f3405692de1 Matthew Garrett  2019-05-20  214  			TPM_MEMUNMAP(mapping, mapping_size);
c46f3405692de1 Matthew Garrett  2019-05-20  215  			mapping_size = halg_size;
c46f3405692de1 Matthew Garrett  2019-05-20  216  			mapping = TPM_MEMREMAP((unsigned long)marker,
c46f3405692de1 Matthew Garrett  2019-05-20  217  					     mapping_size);
c46f3405692de1 Matthew Garrett  2019-05-20  218  			if (!mapping) {
c46f3405692de1 Matthew Garrett  2019-05-20  219  				size = 0;
c46f3405692de1 Matthew Garrett  2019-05-20  220  				goto out;
c46f3405692de1 Matthew Garrett  2019-05-20  221  			}
c46f3405692de1 Matthew Garrett  2019-05-20  222  		} else {
c46f3405692de1 Matthew Garrett  2019-05-20  223  			mapping = marker;
c46f3405692de1 Matthew Garrett  2019-05-20  224  		}
c46f3405692de1 Matthew Garrett  2019-05-20  225  
c46f3405692de1 Matthew Garrett  2019-05-20  226  		memcpy(&halg, mapping, halg_size);
44038bc514a244 Matthew Garrett  2019-05-20  227  		marker = marker + halg_size;
c46f3405692de1 Matthew Garrett  2019-05-20  228  
44038bc514a244 Matthew Garrett  2019-05-20  229  		for (j = 0; j < efispecid->num_algs; j++) {
44038bc514a244 Matthew Garrett  2019-05-20  230  			if (halg == efispecid->digest_sizes[j].alg_id) {
44038bc514a244 Matthew Garrett  2019-05-20  231  				marker +=
44038bc514a244 Matthew Garrett  2019-05-20  232  					efispecid->digest_sizes[j].digest_size;
44038bc514a244 Matthew Garrett  2019-05-20  233  				break;
44038bc514a244 Matthew Garrett  2019-05-20  234  			}
44038bc514a244 Matthew Garrett  2019-05-20  235  		}
44038bc514a244 Matthew Garrett  2019-05-20  236  		/* Algorithm without known length. Such event is unparseable. */
c46f3405692de1 Matthew Garrett  2019-05-20  237  		if (j == efispecid->num_algs) {
c46f3405692de1 Matthew Garrett  2019-05-20  238  			size = 0;
c46f3405692de1 Matthew Garrett  2019-05-20  239  			goto out;
c46f3405692de1 Matthew Garrett  2019-05-20  240  		}
44038bc514a244 Matthew Garrett  2019-05-20  241  	}
44038bc514a244 Matthew Garrett  2019-05-20  242  
c46f3405692de1 Matthew Garrett  2019-05-20  243  	/*
c46f3405692de1 Matthew Garrett  2019-05-20  244  	 * Map the event size - we don't read from the event itself, so
c46f3405692de1 Matthew Garrett  2019-05-20  245  	 * we don't need to map it
c46f3405692de1 Matthew Garrett  2019-05-20  246  	 */
c46f3405692de1 Matthew Garrett  2019-05-20  247  	if (do_mapping) {
c46f3405692de1 Matthew Garrett  2019-05-20  248  		TPM_MEMUNMAP(mapping, mapping_size);
c46f3405692de1 Matthew Garrett  2019-05-20  249  		mapping_size += sizeof(event_field->event_size);
c46f3405692de1 Matthew Garrett  2019-05-20  250  		mapping = TPM_MEMREMAP((unsigned long)marker,
c46f3405692de1 Matthew Garrett  2019-05-20  251  				       mapping_size);
c46f3405692de1 Matthew Garrett  2019-05-20  252  		if (!mapping) {
c46f3405692de1 Matthew Garrett  2019-05-20  253  			size = 0;
c46f3405692de1 Matthew Garrett  2019-05-20  254  			goto out;
c46f3405692de1 Matthew Garrett  2019-05-20  255  		}
c46f3405692de1 Matthew Garrett  2019-05-20  256  	} else {
c46f3405692de1 Matthew Garrett  2019-05-20  257  		mapping = marker;
c46f3405692de1 Matthew Garrett  2019-05-20  258  	}
c46f3405692de1 Matthew Garrett  2019-05-20  259  
c46f3405692de1 Matthew Garrett  2019-05-20  260  	event_field = (struct tcg_event_field *)mapping;
c46f3405692de1 Matthew Garrett  2019-05-20  261  
44038bc514a244 Matthew Garrett  2019-05-20  262  	marker = marker + sizeof(event_field->event_size)
44038bc514a244 Matthew Garrett  2019-05-20  263  		+ event_field->event_size;
44038bc514a244 Matthew Garrett  2019-05-20  264  	size = marker - marker_start;
44038bc514a244 Matthew Garrett  2019-05-20  265  
047d50aee341d9 Peter Jones      2019-10-02  266  	if (event_type == 0 && event_field->event_size == 0)
c46f3405692de1 Matthew Garrett  2019-05-20  267  		size = 0;
047d50aee341d9 Peter Jones      2019-10-02  268  
c46f3405692de1 Matthew Garrett  2019-05-20  269  out:
c46f3405692de1 Matthew Garrett  2019-05-20  270  	if (do_mapping)
c46f3405692de1 Matthew Garrett  2019-05-20  271  		TPM_MEMUNMAP(mapping, mapping_size);
44038bc514a244 Matthew Garrett  2019-05-20  272  	return size;
44038bc514a244 Matthew Garrett  2019-05-20  273  }
c46f3405692de1 Matthew Garrett  2019-05-20  274  

:::::: The code at line 198 was first introduced by commit
:::::: 047d50aee341d940350897c85799e56ae57c3849 efi/tpm: Don't access event->count when it isn't mapped

:::::: TO: Peter Jones <pjones@redhat.com>
:::::: CC: Ingo Molnar <mingo@kernel.org>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 29988 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-01 14:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01 14:35 [linux-next:master 7573/14131] include/linux/tpm_eventlog.h:198:20: warning: taking address of packed member 'count' of class or structure 'tcg_pcr_event2_head' may result in an unaligned pointer value kbuild test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.