From patchwork Tue Oct 3 10:56:54 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: 147813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1998296vqb; Tue, 3 Oct 2023 03:57:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvEPy634zGEpnfpt03UlkNVcUVS9GUGbg+z5pIU0as2iy0MQig2QlDZBVcZGMVQPKNMbuy X-Received: by 2002:a05:6a00:1496:b0:68a:3ba3:e249 with SMTP id v22-20020a056a00149600b0068a3ba3e249mr16107147pfu.16.1696330647828; Tue, 03 Oct 2023 03:57:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696330647; cv=none; d=google.com; s=arc-20160816; b=JuG+eSBnIzHWmkKCiirKvfH0NvyW7lhXJPDCsGbUsYqg3XF5mHhjdp6pRifk71JjyS H85DxOK0YMcbexzkH6Or06jQD9brAheQyUVytvZUIqK4EedNrTUiqYBtt8rc5Od80a+R zjYLm1XnpKXQ9X0340v5iblL5Dy9+/Ia3jzRR2M56Fn49r6IcjmP45ytx5Osgx0twIL3 xL672Uws58C/U34rgkcE8GeW8jBvubrhmOn/c3QX7yAE1TefLbZAvhRn5kQjjEDvSB/K LT+gRrXeG+b88Su1dwik12cYlrRdLR8FBYABuNIJyZdnoJWhp1U91XKJjrTUegMxUVpy 38NQ== 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=U4kqWlKSrKUGHjjrIp64JpYLKcrrQXp4C9HCFKljZwE=; fh=0w/vSzGveF63WplM20DY5d5wouJaaAgj7n4Z4l663/A=; b=rAR1aAy1Oaz1LUruAhI8Ot9xgGUfWDEO+EWJSqurIhBw5ZDy8KcCTvJ5sqD/tRGBwc 9BInnjHovc2UaMqelcH9T1mR8cdR0v/x2NI0Ttfb8MPpUJsBIvwzl5iitX+PfF+LR3te BXhyGrhDzEDSTzFNWrdkJtkCRc9Uxae3EbdQkc35UUpgptnq8l2b4bAINvfwN1MeZZp/ KguPNkd3g7DaY/RK+sUhctD3+B+fPLR7tP+Y2r0dbZOwKHJ+TOqaPeMohNZ/rsora1AG JKtCIPlRP/o94p1lxvNhHnb6KBzar5uBgMXX3XHsXpc2Tcf7VwszzK+U7Ij2S0GJFLg7 H7zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XI3o7enO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id 81-20020a630254000000b00578cc82870asi1148854pgc.344.2023.10.03.03.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 03:57:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XI3o7enO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 B9BB7801C199; Tue, 3 Oct 2023 03:57:25 -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 S239845AbjJCK5F (ORCPT + 18 others); Tue, 3 Oct 2023 06:57:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239735AbjJCK5E (ORCPT ); Tue, 3 Oct 2023 06:57:04 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05D3A9B for ; Tue, 3 Oct 2023 03:57:01 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68061C433CA; Tue, 3 Oct 2023 10:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696330620; bh=L2ltrDergf8j+6fN/XHH5Y2TY5o3ImTEqYPcQIDDz74=; h=Date:From:To:Cc:Subject:From; b=XI3o7enOreh7fRsdaT70e9scAOoD65yQRBnHI6PYbVcep0ISwndyOulaRdbTy/VTF 0U9drLcniIQyOtYmnZjHHNM0cX3J1t8xX/uazdVob2up4RGkLBhod76s+s1+iDsUQL dN01yQ2zvr8ECqcQnAVSH8KQUr6SsXxDNNXQsqYQc/jksSmHJx3H5yk3pf2c9Y2a1K 17BlOVCZDoDyXgKR5wmI0VclvNtJLyP1+ntRipJp4kFsqTQ25kh3yl4FCZrhpVs9r3 1XOq2udkA3et5rTP2CVa8jqSzPzCLPjh2xg2J+ExgVfpFV75GBtuH+dKAgZWo1qYOW GmIlJrrfFpuTg== Date: Tue, 3 Oct 2023 12:56:54 +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 v2][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=-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: 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]); Tue, 03 Oct 2023 03:57:25 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778731407493711006 X-GMAIL-MSGID: 1778731605275389994 `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: | 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`. -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally. Fixes: 34aba2c45024 ("cxgb4/chcr : Register to tls add and del callback") Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva --- Changes in v2: - Update changelog text: mention -Wflex-array-member-not-at-end. v1: - Link: https://lore.kernel.org/linux-hardening/ZRvyysCUTqA7aXN4@work/ 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 {