Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/af_iucv: Use struct_group() to zero struct iucv_sock region

In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memset(), avoid intentionally writing across
neighboring fields.

Add struct_group() to mark the region of struct iucv_sock that gets
initialized to zero. Avoid the future warning:

In function 'fortify_memset_chk',
inlined from 'iucv_sock_alloc' at net/iucv/af_iucv.c:476:2:
./include/linux/fortify-string.h:199:4: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
199 | __write_overflow_field(p_size_field, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Acked-by: Karsten Graul <kgraul@linux.ibm.com>
Link: https://lore.kernel.org/lkml/19ff61a0-0cda-6000-ce56-dc6b367c00d6@linux.ibm.com/
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Kees Cook and committed by
David S. Miller
b5d8cf0a 8f2a83b4

+7 -5
+6 -4
include/net/iucv/af_iucv.h
··· 112 112 113 113 struct iucv_sock { 114 114 struct sock sk; 115 - char src_user_id[8]; 116 - char src_name[8]; 117 - char dst_user_id[8]; 118 - char dst_name[8]; 115 + struct_group(init, 116 + char src_user_id[8]; 117 + char src_name[8]; 118 + char dst_user_id[8]; 119 + char dst_name[8]; 120 + ); 119 121 struct list_head accept_q; 120 122 spinlock_t accept_q_lock; 121 123 struct sock *parent;
+1 -1
net/iucv/af_iucv.c
··· 473 473 atomic_set(&iucv->msg_recv, 0); 474 474 iucv->path = NULL; 475 475 iucv->sk_txnotify = afiucv_hs_callback_txnotify; 476 - memset(&iucv->src_user_id , 0, 32); 476 + memset(&iucv->init, 0, sizeof(iucv->init)); 477 477 if (pr_iucv) 478 478 iucv->transport = AF_IUCV_TRANS_IUCV; 479 479 else