From patchwork Fri Jul 28 15:52:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 1814347 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=bOvOnBw2; dkim-atps=neutral Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RCByX3CQHz1ybX for ; Sat, 29 Jul 2023 01:54:10 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 5014A8443C; Fri, 28 Jul 2023 15:54:05 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 5014A8443C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1690559645; bh=gALNCMeZjaPrACkG/lA+b5WX40NZHtcdQQ4fB62tG8k=; h=From:To:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:Cc:From; b=bOvOnBw2zvGnLGkoBgnpCyrkVfEdXVqojkeu9MPIiCPF4V2IwP8DdzWSTZy2FYDli hSyKjowvV1tiEHP3fGk/u9cXaRCsyWUyzWW1bSA18h2X+wt6vIN/7mTIxzoIhUBJfU mxt4dWbTm+X4TZbP8lL84YfgAvp/+w5zFYANL7V35EZFIM9P8Wh4+ujD/KQh1gc3GA dQHNXpsK8RLEkxpR8N3J+Ll/yRhe9aEPEj7lMbecgJ/C49K9l44OkcR8+Z0/sDa0KA z1KKU/3ohUGC57w3gYA9v8IASui21DZduWEJKzMXdmgPxFlWT6lwB6RFntcwl9tCZ7 62UGoIfHPPNqg== X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mH7ry5D46j-0; Fri, 28 Jul 2023 15:54:04 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp1.osuosl.org (Postfix) with ESMTP id B39758443D; Fri, 28 Jul 2023 15:54:03 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org B39758443D X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 994B61BF28B for ; Fri, 28 Jul 2023 15:53:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 7122840AAE for ; Fri, 28 Jul 2023 15:53:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 7122840AAE X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s62GJssemxlU for ; Fri, 28 Jul 2023 15:53:36 +0000 (UTC) Received: from mgamail.intel.com (unknown [134.134.136.65]) by smtp2.osuosl.org (Postfix) with ESMTPS id 4001740025 for ; Fri, 28 Jul 2023 15:53:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 4001740025 X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="372246657" X-IronPort-AV: E=Sophos;i="6.01,237,1684825200"; d="scan'208";a="372246657" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 08:53:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="727512158" X-IronPort-AV: E=Sophos;i="6.01,237,1684825200"; d="scan'208";a="727512158" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orsmga002.jf.intel.com with ESMTP; 28 Jul 2023 08:53:31 -0700 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Date: Fri, 28 Jul 2023 17:52:04 +0200 Message-ID: <20230728155207.10042-1-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690559616; x=1722095616; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=oQf/S1ueoDews0oxh0qBtYpU3yruH6wicxcwWAyEZqk=; b=cqvS5Nmf5KlLiejrfQrH4H5mUdWAX6BPcffh+8q4J6i0RIO95nV9pDss TmB/SeI2KeKwL07iCFa9fY0c//DL82kexey+LWgRxWUpiO2aNIUPIw2nl uNCpyQKpmEj0ur5RgpNTpdDRk3db+yzeOy+1HwMePLbsurW/qaZwLx5Aa EaNpnH9a5+lfihi1S+ZpE5Sq5lBUElPVqWxV91sUbfPo2hAh4D1CKKD20 mFxxAofM2HrjGb5TPBKzalh8+m4WMSFRvXOj2l0TkEGIw0eIK2EWWxDGY agH/WcbX0/nIP0YzfqX4Gm/WsRnJD3fPjrq3jgISzIDvrRJJ9dDjgMncp g==; X-Mailman-Original-Authentication-Results: smtp2.osuosl.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=cqvS5Nmf Subject: [Intel-wired-lan] [PATCH net-next 0/3] virtchnl: fix fake 1-elem arrays X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kees Cook , Larysa Zaremba , netdev@vger.kernel.org, "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, Andy Shevchenko Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" 6.5-rc1 started spitting warning splats when composing virtchnl messages, precisely on virtchnl_rss_key and virtchnl_lut: [ 84.167709] memcpy: detected field-spanning write (size 52) of single field "vrk->key" at drivers/net/ethernet/intel/iavf/iavf_virtchnl.c:1095 (size 1) [ 84.169915] WARNING: CPU: 3 PID: 11 at drivers/net/ethernet/intel/ iavf/iavf_virtchnl.c:1095 iavf_set_rss_key+0x123/0x140 [iavf] ... [ 84.191982] Call Trace: [ 84.192439] [ 84.192900] ? __warn+0xc9/0x1a0 [ 84.193353] ? iavf_set_rss_key+0x123/0x140 [iavf] [ 84.193818] ? report_bug+0x12c/0x1b0 [ 84.194266] ? handle_bug+0x42/0x70 [ 84.194714] ? exc_invalid_op+0x1a/0x50 [ 84.195149] ? asm_exc_invalid_op+0x1a/0x20 [ 84.195592] ? iavf_set_rss_key+0x123/0x140 [iavf] [ 84.196033] iavf_watchdog_task+0xb0c/0xe00 [iavf] ... [ 84.225476] memcpy: detected field-spanning write (size 64) of single field "vrl->lut" at drivers/net/ethernet/intel/iavf/iavf_virtchnl.c:1127 (size 1) [ 84.227190] WARNING: CPU: 27 PID: 1044 at drivers/net/ethernet/intel/ iavf/iavf_virtchnl.c:1127 iavf_set_rss_lut+0x123/0x140 [iavf] ... [ 84.246601] Call Trace: [ 84.247228] [ 84.247840] ? __warn+0xc9/0x1a0 [ 84.248263] ? iavf_set_rss_lut+0x123/0x140 [iavf] [ 84.248698] ? report_bug+0x12c/0x1b0 [ 84.249122] ? handle_bug+0x42/0x70 [ 84.249549] ? exc_invalid_op+0x1a/0x50 [ 84.249970] ? asm_exc_invalid_op+0x1a/0x20 [ 84.250390] ? iavf_set_rss_lut+0x123/0x140 [iavf] [ 84.250820] iavf_watchdog_task+0xb16/0xe00 [iavf] Gustavo already tried to fix those back in 2021[0][1]. Unfortunately, a VM can run a different kernel than the host, meaning that those structures are sorta ABI. However, it is possible to have proper flex arrays + struct_size() calculations and still send the very same messages with the same sizes. The common rule is: elem[1] -> elem[] size = struct_size() + The "old" size in the current code is calculated 3 different ways for 10 virtchnl structures total. Each commit addresses one of the ways cumulatively instead of per-structure. I was planning to send it to -net initially, but given that virtchnl was renamed from i40evf and got some fat style cleanup commits in the past, it's not very straightforward to even pick appropriate SHAs, not speaking of automatic portability. I may send manual backports for a couple of the latest supported kernels later on if anyone needs it at all. [0] https://lore.kernel.org/all/20210525230912.GA175802@embeddedor [1] https://lore.kernel.org/all/20210525231851.GA176647@embeddedor Alexander Lobakin (3): virtchnl: fix fake 1-elem arrays in structs allocated as `nents + 1` - 1 virtchnl: fix fake 1-elem arrays in structures allocated as `nents + 1` virtchnl: fix fake 1-elem arrays for structures allocated as `nents` .../ethernet/intel/i40e/i40e_virtchnl_pf.c | 9 +- drivers/net/ethernet/intel/iavf/iavf.h | 6 +- drivers/net/ethernet/intel/iavf/iavf_client.c | 4 +- drivers/net/ethernet/intel/iavf/iavf_client.h | 2 +- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 75 +++++------ drivers/net/ethernet/intel/ice/ice_virtchnl.c | 2 +- include/linux/avf/virtchnl.h | 127 +++++++++++------- 7 files changed, 124 insertions(+), 101 deletions(-) Tested-by: Rafal Romanowski