summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavoars@kernel.org>2023-09-15 13:16:26 -0600
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-11-20 11:08:14 +0100
commit56e7424c6efc92e0fcdf5d478a069f1a55dbbdb1 (patch)
treeee23b65eef9c53f7b8d5d5af1a65240ae4f513e1 /net
parent3e51efcb29096b9d6db26455761559c1efa28ef2 (diff)
tipc: Use size_add() in calls to struct_size()
[ Upstream commit 2506a91734754de690869824fb0d1ac592ec1266 ] 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: e034c6d23bc4 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'net')
-rw-r--r--net/tipc/link.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/net/tipc/link.c b/net/tipc/link.c
index 655a2e1b6dfe..d13a85b9cdb2 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -1445,7 +1445,7 @@ u16 tipc_get_gap_ack_blks(struct tipc_gap_ack_blks **ga, struct tipc_link *l,
p = (struct tipc_gap_ack_blks *)msg_data(hdr);
sz = ntohs(p->len);
/* Sanity check */
- if (sz == struct_size(p, gacks, p->ugack_cnt + p->bgack_cnt)) {
+ if (sz == struct_size(p, gacks, size_add(p->ugack_cnt, p->bgack_cnt))) {
/* Good, check if the desired type exists */
if ((uc && p->ugack_cnt) || (!uc && p->bgack_cnt))
goto ok;
@@ -1532,7 +1532,7 @@ static u16 tipc_build_gap_ack_blks(struct tipc_link *l, struct tipc_msg *hdr)
__tipc_build_gap_ack_blks(ga, l, ga->bgack_cnt) : 0;
/* Total len */
- len = struct_size(ga, gacks, ga->bgack_cnt + ga->ugack_cnt);
+ len = struct_size(ga, gacks, size_add(ga->bgack_cnt, ga->ugack_cnt));
ga->len = htons(len);
return len;
}