From patchwork Fri Sep 15 19:16:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13387567 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E32C11094C for ; Fri, 15 Sep 2023 19:15:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 808E2C433C8; Fri, 15 Sep 2023 19:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694805332; bh=EjITR0LTMcwMw0imCdzNOKP5+uLwNDiESLPjL0Q70yw=; h=Date:From:To:Cc:Subject:From; b=uWorQgmu/yJeK1Dvl8+PoM6hv0t5BrzSm+PzI2M7AijSa+s+nBO7dWUQ3TzF3PHBO oKCWtE7f1MwPZbn0aquWNvRMk5FO7mPRMSFueVXwo0DBK+K4HMvr4zCTVNB05kPFSB rvjIzweCakLZF9D/zbkAtl99ZXb1Z6Hmx29kPNGwUVlEGtKNdV+u9N6NqlSaQeSCRD oh7q9DTilSMWYfq6iyL5yoD/qhpNh6ejPed472lmtV5q5QMtlnzzooZSgeZ/R5Uy4o 1glkXDvBhEpm1psOddSxPuyQef+Uz1sW4/IoLlVEk1P7QhVX4CgoMn9XxrmInVFk5p K29FGRVjID9jQ== Date: Fri, 15 Sep 2023 13:16:26 -0600 From: "Gustavo A. R. Silva" To: Jon Maloy , Ying Xue , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] tipc: Use size_add() in calls to struct_size() Message-ID: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-Patchwork-Delegate: kuba@kernel.org 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 Reviewed-by: Kees Cook --- net/tipc/link.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/tipc/link.c b/net/tipc/link.c index e33b4f29f77c..d0143823658d 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c @@ -1446,7 +1446,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; @@ -1533,7 +1533,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; }