Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2093552rdb; Tue, 3 Oct 2023 09:59:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkSoA9OWKLHa+nxxZrljpV0nL8UUi08dsCZUWsUsh0o+CrkRNJi508xLGJHLRn0JB2XaNG X-Received: by 2002:a05:6a20:8422:b0:140:730b:4b3f with SMTP id c34-20020a056a20842200b00140730b4b3fmr89555pzd.1.1696352369934; Tue, 03 Oct 2023 09:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696352369; cv=none; d=google.com; s=arc-20160816; b=V/il1qXGt2igc0829sl7UwlMkoKT1+iOULx42ci5w+/i1hVngDAt54IVw/mVk8/wPF lIqRzdfQ9UDHzrEob0S3jJtvrdW/uVvx/b+1zz1ZkpkiXM/9eSUwIFhhx/NBnz0lf4bm FwPES97IxkfRiPbcGwliTWarvUJ1+k7yN+gaIdBJL1FGzWwM/hoRZsoVLAOeA6tbhDXw oFxLyc9Bnjute/7cPEGKNuTr/4lK10D0UySMfgy8Q1fgciVfHsuzbQKE6UhD0vTTN299 rmczypOR4w+v2Vxz2/lCPEvmrJXJMe4vPAM3ZtxONfbbW6KmJfVGWTOu/5BeG04fWkHZ 7Eqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=VOVByuProAG6GihYbShg28rrFXeHu1PVU/N0SfiPbHI=; fh=qKpiE/5rRr8LwaF0A4Zh4IyCCfoQTUMLxgG6Q3Hg90E=; b=LA2/VDAg4LE/KpTRzAzv8mQo0ceUhGReN516suxap6NRRjecKtIzVE5VBQNcEY9dsD 2pmY8jCXadq4QgjP0qy/RS2aV8nrARx9yZEIOmZaOzNqeS9xDaNQLgMTPLahzVjOC/9e D190h2toXshBSygTGxfi8MrfhfNGPO1uVHwKosEC7oDrNywVzyyBi2B/lJi2rxTms2Dz BRtiwBfXjijUlyoG+BgdEhsSSdSBLUqcR0GFNDr002k8D0wR96M2A1qYHMCxj3vZ23Wb pNwAyO/tW45j0q2n09AKRt6wPnPVt0PiCOxANTVqfMztAuYScHO1u5H6zS2UoW/RqDkt NdbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id by15-20020a056a00400f00b00690dbcb75d8si1715267pfb.386.2023.10.03.09.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 09:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E2C78808DB7A; Tue, 3 Oct 2023 09:59:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240546AbjJCQ71 (ORCPT + 99 others); Tue, 3 Oct 2023 12:59:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240537AbjJCQ7X (ORCPT ); Tue, 3 Oct 2023 12:59:23 -0400 Received: from us-smtp-delivery-44.mimecast.com (unknown [207.211.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1B0AA7 for ; Tue, 3 Oct 2023 09:59:19 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-689-xuwW08IkPQyY_aY8uirDQw-1; Tue, 03 Oct 2023 12:59:02 -0400 X-MC-Unique: xuwW08IkPQyY_aY8uirDQw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B175F3C1ACE5; Tue, 3 Oct 2023 16:58:44 +0000 (UTC) Received: from hog (unknown [10.45.224.63]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70EB64A9B0C; Tue, 3 Oct 2023 16:58:42 +0000 (UTC) Date: Tue, 3 Oct 2023 18:58:40 +0200 From: Sabrina Dubroca To: "Gustavo A. R. Silva" Cc: Ayush Sawal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rohit Maheshwari , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2][next] cxgb4/ch_ktls: Fix undefined behavior bug in struct chcr_ktls_ofld_ctx_tx Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_RPBL,RDNS_NONE,SPF_HELO_NONE,SPF_NONE autolearn=no 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 (howler.vger.email [0.0.0.0]); Tue, 03 Oct 2023 09:59:29 -0700 (PDT) 2023-10-03, 12:56:54 +0200, Gustavo A. R. Silva wrote: > `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`. AFAIU, chcr_ktls_ofld_ctx_tx just misuses the extra space allocated by tls_set_device_offload. There's no bug, but the code is a bit confusing. I don't think this patch works, since chcr_ktls doesn't allocate its own memory for chcr_ktls_ofld_ctx_tx. As part of a series of cleanups that I'll submit soon (hopefully this week), I updated chcr_ktls to use the driver_state part of tls_offload_context_tx (instead of the cast in chcr_get_ktls_tx_context), and then removed the flexarrays from tls_offload_context_tx and tls_offload_context_rx (since they're actually a fixed size). -- Sabrina