From patchwork Tue Oct 3 10:54:02 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: 147806 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1997131vqb; Tue, 3 Oct 2023 03:54:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIsd1iPGQ+4c3F6z0UlJY9iHxx5IUNURSD2L/FKWhezrPwZXwa5maJ8NMe2wpmc9RCotoH X-Received: by 2002:a05:6a20:1441:b0:14c:a2e1:65fd with SMTP id a1-20020a056a20144100b0014ca2e165fdmr13876797pzi.9.1696330458778; Tue, 03 Oct 2023 03:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696330458; cv=none; d=google.com; s=arc-20160816; b=i55prysvJWgugQUKa5PBKK+CSYRpS0KZnYFwQmvsI/QIoLoTeYbJ1pxy/msFvQDVIE wSv4cCGCajhS0nBf+sm1SGquWGJUiDiEAIbL5k0dm37MRG4vr+bKrdB2U4sOpnUw6KsN ChqliG3Lvu/ZWPm3G8rWj9YySaqWhd5ed4x9U4Ws4+u6A25oXbRhD4hGpW89A+/oJAeH tz0oAuQ6bcxJEEMF06effPYHy+lM7RRmH4PrVzp4rN6mGw4zhUjMpRnVDmnyp+9pPZVG OWXnliWW39QxcXEieIIEE1VNRVDgMOaW5FLh/ep5Qwjg6IECLGMM0DNL03aMakb/Lgfi Rh0g== 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=Bk4pziM6koP+b+6Lpf8Uh7ndvtN28Qndiumkq8lPuyk=; fh=0w/vSzGveF63WplM20DY5d5wouJaaAgj7n4Z4l663/A=; b=kVkpBHeoF5a3hI0Lp/yde2MWIQY6lstJ4AsGq5yJDL6QA+/HQNpvcMfKvKalrkFcKE hvaPNOkbHrTVE6RWevdAxMVSmWbBLz5ZApWcXDSDmCwLwFiI2ElYWSvpDjUw7a80DHqT dlnbsdSez0umlZU7Vx3HCUT+ixxd/XoX0F+x3wT+oMYiJiSpS1xb5dUk8eC+nGtSZnzB 3jGV+/hVPrZlUgJcl9LhSUbEJhgq3pj/O/iQLiO+fJT5c2nUCXKcdtHVOHMqBKhx0+dz Iil0ZwR0d6bWqV2LxWH0GluScYB3AT4FjXgP+/FsCvOdOnn3vFdwKouqLS8vNOGbz7fE +uuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="nMK2TiL/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n22-20020a170902969600b001c62cfff795si1089443plp.429.2023.10.03.03.54.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 03:54:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="nMK2TiL/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id CC44A812A951; Tue, 3 Oct 2023 03:54:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239709AbjJCKyP (ORCPT + 19 others); Tue, 3 Oct 2023 06:54:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbjJCKyO (ORCPT ); Tue, 3 Oct 2023 06:54:14 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6039EAF for ; Tue, 3 Oct 2023 03:54:08 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE85CC433C7; Tue, 3 Oct 2023 10:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696330448; bh=0cPg/g9l5wi2azSbvT6fsYacFP0mkqp/bwFYc7a8Fw4=; h=Date:From:To:Cc:Subject:From; b=nMK2TiL/Fz7K5bEEz0fXBjnhoobDkzVdSItGSU2zz1BalGpxKHh4pHVDhJe7S5RdV Ozl+WZgrMFWZtFv2ZqSgNlm4BQK2iEg1CyIiE+vs5TqT8TY57g6TxSE8WZmorcMoZa n81gfyQS0ABqWA8ASiyxqu8ynYv4x9Mis+bd6OI//QkQkzjAOkizbwPi7yR4kM8Dsv PdjLH7nyzHaOVvMqEzUg/8Clh+I74kO/bLKk2w55ayWULYpIIZBaWqaJMLeESHRhBO 8a2hec7y5wLTDUEZhUsSPdsBLSpx5TdlwixdWRDFurv9FnaiWH2Et/Nz+DjBFL0SFE nodU2AT6zNfiQ== Date: Tue, 3 Oct 2023 12:54:02 +0200 From: "Gustavo A. R. Silva" To: Ayush Sawal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rohit Maheshwari Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] cxgb4/ch_ktls: Fix undefined behavior bug in struct chcr_ktls_ofld_ctx_tx Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 03 Oct 2023 03:54:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778731407493711006 X-GMAIL-MSGID: 1778731407493711006 `struct tls_offload_context_tx` is a flexible structure, which means that it contains a flexible-array member at the bottom. This could potentially lead to an overwrite of the objects following `base` in `struct chcr_ktls_ofld_ctx_tx` at run-time. Notice that flexible-array member `driver_state` in `struct tls_offload_context_tx` can grow up to 16 bytes at run-time: | include/net/tls.h-170: | #define TLS_DRIVER_STATE_SIZE_TX 16 | include/net/tls.h-173: | #define TLS_OFFLOAD_CONTEXT_SIZE_TX \ | (sizeof(struct tls_offload_context_tx) + TLS_DRIVER_STATE_SIZE_TX) | net/tls/tls_device.c-1119: | offload_ctx = kzalloc(TLS_OFFLOAD_CONTEXT_SIZE_TX, GFP_KERNEL); Fix this by placing the declaration of object `base` at the end of `struct chcr_ktls_ofld_ctx_tx`. Fixes: 34aba2c45024 ("cxgb4/chcr : Register to tls add and del callback") Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva --- drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h b/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h index 10572dc55365..35e34e3db663 100644 --- a/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h +++ b/drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.h @@ -68,8 +68,8 @@ struct chcr_ktls_info { }; struct chcr_ktls_ofld_ctx_tx { - struct tls_offload_context_tx base; struct chcr_ktls_info *chcr_info; + struct tls_offload_context_tx base; }; struct chcr_ktls_uld_ctx {