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: 140643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1278736vqi; Fri, 15 Sep 2023 12:41:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQYNItR/Y0eGm+Q9LjNxNjxzJ5qXp08mUvyeV85l8tfkaILN1Wprica8jnbWm0uTEWcm46 X-Received: by 2002:a05:6358:c23:b0:142:eb11:b0b8 with SMTP id f35-20020a0563580c2300b00142eb11b0b8mr2322790rwj.1.1694806861847; Fri, 15 Sep 2023 12:41:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694806861; cv=none; d=google.com; s=arc-20160816; b=WP3W38Bb+68HIC8L1t30LS4Bf0LwkC1YmEFtvjPsaPyff+zVCteA4V5en7HYUa/L1z QTSZyhh3TsPmOd4rqm0NaI/s2rHJ3uqdUuc7BgbkP0tg+ak8IaA9FNuhjeIKGdiTsY+k wVr/JT6IkkKRDkB1GRHyBDP416RcciTesN6R6dk6NIDyfJ+JVUws7J1bncBQWmDeGNyN OjSc3t6MuvE6GE41/mPQkk0GXdNDU7hA1C/ZKjaH/ESk2RUbTer/ccC30FEu7sOYJ/Ty Bvv5OGJqvVVsS6D3ignZKrdVHMWP+YVTphG+1GaSPB17dZ+KEgHo3Yqn1USGWx2EN7+2 s/lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=1CDnzkpl0pwkHalBKblw9/EEBE9XpiwR7Al0enTwGJI=; fh=vUK4GlPt8q1VH4I1D4K73eEYd6F2evIjos414riB/CU=; b=MVceLYz7aXKqVPGHgmQ1E0CsEfTIEU6tSZ+f3FBuD6kVFPIS7w78nqQRrGiEx7Zp4i V1y+pSgagRN8h/+Z9XPnNhDFpv6O27QgxkN41XaoN1+aExEKKxIwVQlcIJmZRQ+EJ/1D n+G29EdmH0zP1jO92c4dB0ngH8c/2MUsiPypa8fNMfB10sZZycgSFzdT2uPG8Srwc7oE A2UFMc9EPjzND1ipbnRN/jj6QFxrlcm/Y+aYJD0nEPMDwONVVqGZi1PDWZTzMBsCAjlK ncb2pm0Wt7X3BZXwBF0lBZYM+UTwbKFrjdmyXSWN/wta0tWGdl6mZj+eqo9JjMbV0HIW S3pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uWorQgmu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y124-20020a633282000000b005778df5647dsi3626274pgy.401.2023.09.15.12.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 12:41:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uWorQgmu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9BFD68258C83; Fri, 15 Sep 2023 12:16:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234465AbjIOTPr (ORCPT + 30 others); Fri, 15 Sep 2023 15:15:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237082AbjIOTPj (ORCPT ); Fri, 15 Sep 2023 15:15:39 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFE0E71; Fri, 15 Sep 2023 12:15:33 -0700 (PDT) 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: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 12:16:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777133799824561181 X-GMAIL-MSGID: 1777133799824561181 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; }