From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8091DC54E67 for ; Tue, 26 Mar 2024 16:42:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 4606140196; Tue, 26 Mar 2024 16:42:04 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Nnmu3VmG0Flm; Tue, 26 Mar 2024 16:42:02 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.166.34; helo=ash.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 4F32A403FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1711471322; bh=+3u80osllA5bXqBjW+TfyLjU+e/Biv5uQy+ppjZ3NtE=; h=From:To:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=XdoBWuAZr9rqra2bs/5E2f44atymcy9xse6+33EjUeojfKDxOjVQMircb5zGUswhR eWLib8NmpQshqNdZe4/zotN4/G6tVihPWOxRI/xUVjtv15hnQ/veYlikhfmwXPiqnD VTUBuPiNTq6E806+GBoY65fHv2/gD8133cWG5YFpZFSFSpsMS/6/r/NOOL2305YjIr h4KdnuC42Zg5sKjEqVtNjiDcaXyPAN/pPoe/AIpTHitERlkGHloO+s3W0dA8VS0RIU AYEZkjkPlkTxOTMXmGHf31jQ0Unbf3I3xUavkOUMepsb7x3QQ/+JQOTz3ob/wF76gF rQWVcM8sONkDA== Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp2.osuosl.org (Postfix) with ESMTP id 4F32A403FC; Tue, 26 Mar 2024 16:42:02 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id F29C61BF364 for ; Tue, 26 Mar 2024 16:42:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id EA16860ABE for ; Tue, 26 Mar 2024 16:41:59 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id W0oh8Jv6_4_B for ; Tue, 26 Mar 2024 16:41:59 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=192.198.163.8; helo=mgamail.intel.com; envelope-from=aleksander.lobakin@intel.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 4677A605DE DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4677A605DE Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4677A605DE for ; Tue, 26 Mar 2024 16:41:59 +0000 (UTC) X-CSE-ConnectionGUID: 1yVD7NLPTEmMOidBAhHQLA== X-CSE-MsgGUID: aJb6AhmKQ7qNdvZNdWFU8g== X-IronPort-AV: E=McAfee;i="6600,9927,11025"; a="24023307" X-IronPort-AV: E=Sophos;i="6.07,156,1708416000"; d="scan'208";a="24023307" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 09:41:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,156,1708416000"; d="scan'208";a="20667393" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa003.jf.intel.com with ESMTP; 26 Mar 2024 09:41:45 -0700 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Date: Tue, 26 Mar 2024 17:41:14 +0100 Message-ID: <20240326164116.645718-2-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240326164116.645718-1-aleksander.lobakin@intel.com> References: <20240326164116.645718-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=1711471319; x=1743007319; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WzwSFT39ppUt+G6VUM5qkC+LZ2l/47JC71a7MRgYP54=; b=DCIx1zgSW0D15XM2zWiKQIfPV1SR6JqlAhfN0+CBewZu1t4sxab5HbJ2 ElCqFyuypR11btLuN5IKDvLw+jNPE8CJwRUeEDXBmb2NfV9bUvIWCnajp cJCX9GV0EaIw9xH1j0cXlfARgq4alkmdbtJ3QfvK2t5Qh7CHbA9tee71Z 5vdAH6+rCHFj8ZQ/Jmpg2J8OX66lJivSsPgzRPHFtZ/83F0lmKaQz/9Fx NYoCUQvYXcjuoI3ESYu5tqQFf/O2eRyJPpXqytID9fvvnLjccrCZInyrO Q3GgsEjvcVlDDeFEG5DzAvOLEbYRvRab3zl7L1di2zi4JVBd2uKXrstrw A==; X-Mailman-Original-Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=intel.com X-Mailman-Original-Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=DCIx1zgS Subject: [Intel-wired-lan] [PATCH net-next 1/3] compiler_types: add Endianness-dependent __counted_by_{le, be} 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 , netdev@vger.kernel.org, "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, Nathan Chancellor , Alexander Lobakin , intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, Simon Horman , nex.sw.ncis.osdt.itp.upstreaming@intel.com Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" Some structures contain flexible arrays at the end and the counter for them, but the counter has explicit Endianness and thus __counted_by() can't be used directly. To increase test coverage for potential problems without breaking anything, introduce __counted_by_{le,be}() defined depending on platform's Endianness to either __counted_by() when applicable or noop otherwise. Maybe it would be a good idea to introduce such attributes on compiler level if possible, but for now let's stop on what we have. Acked-by: Kees Cook Signed-off-by: Alexander Lobakin --- Documentation/conf.py | 2 ++ scripts/kernel-doc | 1 + include/linux/compiler_types.h | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/Documentation/conf.py b/Documentation/conf.py index d148f3e8dd57..0c2205d536b3 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -75,6 +75,8 @@ if major >= 3: "__rcu", "__user", "__force", + "__counted_by_le", + "__counted_by_be", # include/linux/compiler_attributes.h: "__alias", diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 967f1abb0edb..1474e95dbe4f 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -1143,6 +1143,7 @@ sub dump_struct($$) { $members =~ s/\s*$attribute/ /gi; $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; $members =~ s/\s*__counted_by\s*\([^;]*\)/ /gos; + $members =~ s/\s*__counted_by_(le|be)\s*\([^;]*\)/ /gos; $members =~ s/\s*__packed\s*/ /gos; $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 2abaa3a825a9..a29ba6ef1e27 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -282,6 +282,17 @@ struct ftrace_likely_data { #define __no_sanitize_or_inline __always_inline #endif +/* + * Apply __counted_by() when the Endianness matches to increase test coverage. + */ +#ifdef __LITTLE_ENDIAN +#define __counted_by_le(member) __counted_by(member) +#define __counted_by_be(member) +#else +#define __counted_by_le(member) +#define __counted_by_be(member) __counted_by(member) +#endif + /* Do not trap wrapping arithmetic within an annotated function. */ #ifdef CONFIG_UBSAN_SIGNED_WRAP # define __signed_wrap __attribute__((no_sanitize("signed-integer-overflow"))) -- 2.44.0