Skip to content

Commit 5140aaa

Browse files
keesdavem330
authored andcommitted
s390: iucv: Avoid field over-reading memcpy()
In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally reading across neighboring array fields. Add a wrapping struct to serve as the memcpy() source so the compiler can perform appropriate bounds checking, avoiding this future warning: In function '__fortify_memcpy', inlined from 'iucv_message_pending' at net/iucv/iucv.c:1663:4: ./include/linux/fortify-string.h:246:4: error: call to '__read_overflow2_field' declared with attribute error: detected read beyond size of field (2nd parameter) Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Karsten Graul <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6dce38b commit 5140aaa

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

net/iucv/iucv.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,14 +1635,16 @@ struct iucv_message_pending {
16351635
u8 iptype;
16361636
u32 ipmsgid;
16371637
u32 iptrgcls;
1638-
union {
1639-
u32 iprmmsg1_u32;
1640-
u8 iprmmsg1[4];
1641-
} ln1msg1;
1642-
union {
1643-
u32 ipbfln1f;
1644-
u8 iprmmsg2[4];
1645-
} ln1msg2;
1638+
struct {
1639+
union {
1640+
u32 iprmmsg1_u32;
1641+
u8 iprmmsg1[4];
1642+
} ln1msg1;
1643+
union {
1644+
u32 ipbfln1f;
1645+
u8 iprmmsg2[4];
1646+
} ln1msg2;
1647+
} rmmsg;
16461648
u32 res1[3];
16471649
u32 ipbfln2f;
16481650
u8 ippollfg;
@@ -1660,10 +1662,10 @@ static void iucv_message_pending(struct iucv_irq_data *data)
16601662
msg.id = imp->ipmsgid;
16611663
msg.class = imp->iptrgcls;
16621664
if (imp->ipflags1 & IUCV_IPRMDATA) {
1663-
memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
1665+
memcpy(msg.rmmsg, &imp->rmmsg, 8);
16641666
msg.length = 8;
16651667
} else
1666-
msg.length = imp->ln1msg2.ipbfln1f;
1668+
msg.length = imp->rmmsg.ln1msg2.ipbfln1f;
16671669
msg.reply_size = imp->ipbfln2f;
16681670
path->handler->message_pending(path, &msg);
16691671
}

0 commit comments

Comments
 (0)