Skip to content

Commit 2506a91

Browse files
GustavoARSilvadavem330
authored andcommitted
tipc: Use size_add() in calls to struct_size()
If, for any reason, the open-coded arithmetic causes a wraparound, the protection that `struct_size()` adds against potential integer overflows is defeated. Fix this by hardening call to `struct_size()` with `size_add()`. Fixes: e034c6d ("tipc: Use struct_size() helper") Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a271325 commit 2506a91

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

net/tipc/link.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ u16 tipc_get_gap_ack_blks(struct tipc_gap_ack_blks **ga, struct tipc_link *l,
14461446
p = (struct tipc_gap_ack_blks *)msg_data(hdr);
14471447
sz = ntohs(p->len);
14481448
/* Sanity check */
1449-
if (sz == struct_size(p, gacks, p->ugack_cnt + p->bgack_cnt)) {
1449+
if (sz == struct_size(p, gacks, size_add(p->ugack_cnt, p->bgack_cnt))) {
14501450
/* Good, check if the desired type exists */
14511451
if ((uc && p->ugack_cnt) || (!uc && p->bgack_cnt))
14521452
goto ok;
@@ -1533,7 +1533,7 @@ static u16 tipc_build_gap_ack_blks(struct tipc_link *l, struct tipc_msg *hdr)
15331533
__tipc_build_gap_ack_blks(ga, l, ga->bgack_cnt) : 0;
15341534

15351535
/* Total len */
1536-
len = struct_size(ga, gacks, ga->bgack_cnt + ga->ugack_cnt);
1536+
len = struct_size(ga, gacks, size_add(ga->bgack_cnt, ga->ugack_cnt));
15371537
ga->len = htons(len);
15381538
return len;
15391539
}

0 commit comments

Comments
 (0)