Message ID | ZQSspmE8Ww8/UNkH@work |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1268058vqi; Fri, 15 Sep 2023 12:19:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmURJIzLSoeRmQCiqr42iAClKd8W0yzvMg04j20rUBzDvG1YtOUvL+yuAhgBmfb5UtQXR6 X-Received: by 2002:a05:6a00:1704:b0:690:2ecd:a595 with SMTP id h4-20020a056a00170400b006902ecda595mr2987022pfc.21.1694805559190; Fri, 15 Sep 2023 12:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694805559; cv=none; d=google.com; s=arc-20160816; b=lr1TDx03ZzscvcYIJfvrPV5oJxFv5JdarPV48ou/LeHP41ymGeI9VW1aoQavAWxHq8 v0oz8hyJfCman6/j/Q/X3NE15fmI8N4CdlFbxs2tkoMT0bUN1cHhd5A3U2zhg3aaqQ/n VQ3FEKv/EJo/wEv1+T2F4odTb5HbNINXIk5kDoM4zc4jeFcaw34cRx+5Pq/L0ceNuzRi Qbx+SbrPqy0nZvASVjJGOea/ANqkAjhFIB0XeyIqUg6xuBLHtEi2UQPPXh/vV/haWDJu LA1a/vKl2MBSL1/zcxvhCdkrYyji/D0Oh/O1oJQcmri203qndZm92NTnzJ/yb9kWlLBr UZMQ== 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=aUTdfjO58DmBh0Q3FgnYhXCLADwm6klqfmcmyV6BAD8=; fh=etOqOXmTvs0JX7Vr3bpBSRqeURO2Y7PyctNSnEcDQyM=; b=Hvi1F86ZB0RHayFo6ZtaOcgcf3FTZjX8mgahtCrPpb5caVjNzc5o+L+zeRoFjaYY/L di+6GPUH+OQBaRYo+Wvk6iRLRVwam8YsSLh8tyswIPHHJx5WfIFBONKlvybhQUMdZmaI KyOlpkQWLzvPygEXlihe8vbXUdS5vOc5HLkYE4K/PVdjP7kY4b2QTVKTJ62LrelueHvU flFyPFui3uamXWOmI4eJ8In30SZK6zY0QYelx0UYO/fHJWHT79Cn4Eb90BGZsJTizbOy dA0D0X6TE+KPP38MmhVReXQp234p25eq/QRphlMw2tQlm5qYRuEnUyNVh41DJMDd9957 O7yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ROjc3G6v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id 201-20020a6302d2000000b0056da0ae25casi3681410pgc.327.2023.09.15.12.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 12:19:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ROjc3G6v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 0ADF880A4165; Fri, 15 Sep 2023 12:12:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234465AbjIOTMC (ORCPT <rfc822;ruipengqi7@gmail.com> + 30 others); Fri, 15 Sep 2023 15:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237084AbjIOTLt (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 15 Sep 2023 15:11:49 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B62EFFB; Fri, 15 Sep 2023 12:11:44 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58F84C433C7; Fri, 15 Sep 2023 19:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694805104; bh=IIDXBilgYAneCN/K2/MuOtg+9tUcnGL2d4QYXB9Cw5E=; h=Date:From:To:Cc:Subject:From; b=ROjc3G6vf0mbKgyCUv2ffJE3OCLUUI8UgG1FpZlN7sUBj3U60h82ohjf+dQwDwIr5 mjY3eC4WjOluKDZUZWZ/s+prYh1hQe/ABLGpmi87IQttMOGklRePtm11Jplsi7WdOO sgbXBJ4cZfXfMyhRk/ByV8r7qJWs3Z+h7yOwIiy+Cfjro97ozQLM71Z7G58QLqHcnD hrRfPRja3Lp2hBof2+z43xZ2PDB0aweG3K/ab3U5qd7WHrIjZbr8R6OQTFdcn5uq22 do8ziQM5OrWT97WPF/CWRyYMAtOjvVT907dQSdZ0ltR3AZV8zj8+lHi2I7q+1q+91d yazLwwwgtzFdA== Date: Fri, 15 Sep 2023 13:12:38 -0600 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Boris Pismenny <borisp@nvidia.com>, John Fastabend <john.fastabend@gmail.com>, Jakub Kicinski <kuba@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com> Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH][next] tls: Use size_add() in call to struct_size() Message-ID: <ZQSspmE8Ww8/UNkH@work> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 15 Sep 2023 12:12:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777132434002850110 X-GMAIL-MSGID: 1777132434002850110 |
Series |
[next] tls: Use size_add() in call to struct_size()
|
|
Commit Message
Gustavo A. R. Silva
Sept. 15, 2023, 7:12 p.m. UTC
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: b89fec54fd61 ("tls: rx: wrap decrypt params in a struct")
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
net/tls/tls_sw.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Sep 15, 2023 at 01:12:38PM -0600, Gustavo A. R. Silva wrote: > 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: b89fec54fd61 ("tls: rx: wrap decrypt params in a struct") > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org>
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index d1fc295b83b5..270712b8d391 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -1487,7 +1487,7 @@ static int tls_decrypt_sg(struct sock *sk, struct iov_iter *out_iov, */ aead_size = sizeof(*aead_req) + crypto_aead_reqsize(ctx->aead_recv); aead_size = ALIGN(aead_size, __alignof__(*dctx)); - mem = kmalloc(aead_size + struct_size(dctx, sg, n_sgin + n_sgout), + mem = kmalloc(aead_size + struct_size(dctx, sg, size_add(n_sgin, n_sgout)), sk->sk_allocation); if (!mem) { err = -ENOMEM;