Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3462134lqp; Tue, 26 Mar 2024 09:42:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUFbpp8SdZDiB5FpZKohqZcWo1HLarYPFoZ2BjMeQ0/nmC6FrB048D2eVxnsHTFPvxwPAxbKS6e1LyLH9A3qMHRbriwzxKxUvKbOmvnBw== X-Google-Smtp-Source: AGHT+IHHF/6yArBbnXCLwpU3Yj4p1/YnqqA3JcFMq1fMQ9KC5QFoGfns9zusUReMB2jX0RnBaLeV X-Received: by 2002:a17:906:3bd6:b0:a46:9773:81ef with SMTP id v22-20020a1709063bd600b00a46977381efmr5675430ejf.71.1711471370001; Tue, 26 Mar 2024 09:42:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711471369; cv=pass; d=google.com; s=arc-20160816; b=JCyWSAJKaOLq5LEgeq3ZoSp7/B+2U83ImrprNDKPKbQpQSKcCi3lu9zKJILtJuj7Xd 5xvaXX6dpb7iq4IyO5WOMF4SFIlgeDRx8ow9SIyh4MBOJkQSiNBr1UVa0XuepO012r1S 1lhH6DbiBmqT7y8bnWAfHVDudeGY3bX4OjOD1fUk5a+0Y3T7D4aHw6wpju0Di9Mp781b 5VN33cxR+g4uNRYLVsCbzyb1i/qAihUSzvfVB34EcctrKaHjGycLlD+aE1UMun0iC6j9 OmegCQPeB3O/Dl+Qctsxedhq1dg5f1ZE/Awal6n5ap3t0RsAJY9f3uhfX5fLfUxk4NsB Ezsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+3u80osllA5bXqBjW+TfyLjU+e/Biv5uQy+ppjZ3NtE=; fh=HYT/VJW8qiUDD5+/85IOy803Q4EzLEkNmonFlu142Og=; b=F5q7AYy003Kud+GWHCl1IY+dRVJfnLWmfuIWvLacK0RLgQ4gAc9WPys04tg58FivvH 80nf+XLng7wUC1l7eeRvaaT861pYvmvqdqtdgn/xoykTrY5/yR4RcEvVdj3kZRHxsm+O xDD9VrzMqi0lw5IgfIuFI8hL5uxtZJKczfozGho/ZQOzPFUKV/jWb4fLyNG0aVm852/h raIC1rUeXaJLdzO/fy7NGD1d5/vxfzSPepNJuAr4BlWr7mSVcQB1ScoKZV4Agn0tvOP7 WhGh0Z2vm09Rpn7RicTC2i9v+E7BXKW/nBMCiQ2AjnQXkaou1j9inp1SZ0MSPsohjj+6 OAeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GesR1+1j; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-119488-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id mc2-20020a170906eb4200b00a451e906d93si3636353ejb.965.2024.03.26.09.42.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 09:42:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119488-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GesR1+1j; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-119488-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 564171F81F83 for ; Tue, 26 Mar 2024 16:42:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 509261C695; Tue, 26 Mar 2024 16:42:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GesR1+1j" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A85C3A95B; Tue, 26 Mar 2024 16:41:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711471321; cv=none; b=QJJFUwTQ1tI8pSAqf/ErYDqaLNZ5bmUUWujBz1A/exAt3zffacgw/m5zqxoKubldHSewPgMCgGQ82e1YMThjoLL9oZaVIOpqjvNNuCvWyYyumYIj3pEEQrLFo4RK6Koylu1ayT8P0zj/hrSVqHf3r3/pcWtAeEpjLidqNOseHZc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711471321; c=relaxed/simple; bh=WzwSFT39ppUt+G6VUM5qkC+LZ2l/47JC71a7MRgYP54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iqASJGzyuGYYdTFh1tTqvI0bw7RuYlRoxvK+3IIjL81sp6Y9EZBtnwIuNnnw2m9JUiMx+fUQ+4SRH45KU16b57RM9yif/Nwk8zUWovO6FSOoGtKy45kDkYn6z+LhbRHPOSYtfKkxq7Fs4MqZdJ0WMQljwHCa8Z9jZKj3tzp2BSs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GesR1+1j; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711471320; x=1743007320; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WzwSFT39ppUt+G6VUM5qkC+LZ2l/47JC71a7MRgYP54=; b=GesR1+1jw0PXdwQJHLor6wD0Sx7gBgi/MHyRKmTLL/eH6tQTmOFld/Do 0QpENyhDKn8dTBfVKc4ut1kx+/ahrAK+sEFca6gmH/Mb0xJ4WzrG5eepC 5YMXvNGvvJZyzioklKTqBHCfSV7NB95hMz8W72cjX8kJ76ixgjxGD8wqd qcFRvjO5Bb2N2ErjzLBwoQE6AhCLDeXSOQLejePio9oGwnuLN+O6/lRO+ ANx0HPrO3E4yoyqKba6EqHWrA73wuCFrKn8EbGtj/Brrf7kO3VZjrUn/3 3Sf/7ppWYV1dGlSylqVyBDbMN9yQ0Uu7GSxcvXGNhdL2CS40KBKXuvKqS g==; X-CSE-ConnectionGUID: YH9nSiARRIC7ZANllyn51w== X-CSE-MsgGUID: BvJ2qqq1TTyWC1zMpc1UzQ== X-IronPort-AV: E=McAfee;i="6600,9927,11025"; a="24023305" X-IronPort-AV: E=Sophos;i="6.07,156,1708416000"; d="scan'208";a="24023305" 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 Cc: Alexander Lobakin , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Simon Horman , nex.sw.ncis.osdt.itp.upstreaming@intel.com, intel-wired-lan@lists.osuosl.org, linux-hardening@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/3] compiler_types: add Endianness-dependent __counted_by_{le,be} 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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