Received: by 2002:ab2:6991:0:b0:1f2:fff1:ace7 with SMTP id v17csp102647lqo; Wed, 27 Mar 2024 08:03:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW6KIBLiluzysOUJpTTmfX9sbjgJ7YAf5LvwIBJVMF0ufpWehfShCesr6eSNjpU9PHDcBt659KRRY9Z90wUhxH9EOsZO/2hwY6S3CcYIw== X-Google-Smtp-Source: AGHT+IFXC3+T34AIju8QDJZjs5+GPb8fHAh7ZaO/JKpnvhWgKvx5fruWDsNPzrELzfmvpQUbnMaZ X-Received: by 2002:a05:6512:610:b0:515:b73e:84aa with SMTP id b16-20020a056512061000b00515b73e84aamr3071346lfe.39.1711551804091; Wed, 27 Mar 2024 08:03:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711551804; cv=pass; d=google.com; s=arc-20160816; b=Bqlrgl+l8kIcc201Osb4x2/9w/bii97ro5hSCcG+s0ykpf9KDzRTDw3tgrgeuYxKfG ttMw1Jo+99IQyvZmjWQUUr+3lQNufZkqIbGETyNcTaRn3Uo33A5sw2M0Fqqp/ruDhp9R 3+cwrYeYwFaoxx2U7e+BA3gl/okofWIxl9iEuu8opcdAgJv95cKUXdJm/MqPYEUy7Gmm UDgxoxKHcutXfy3YRZ6gAxQVt7HiTJMWtR+WmtP7cpXePjrSQ0V/kzCmI5pIXYT3mGiP shPXBEwcQoTHGOQQzd3OnruGXLnO2o1uCZEGuYmwfdL0If2PFQOdUJCmaz4Gd5w9y0PS aXCQ== 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=bhtrMxRIBaBdE7YxwV2QkkpGLkKtGlJ4PAWik8sHAL8=; fh=HYT/VJW8qiUDD5+/85IOy803Q4EzLEkNmonFlu142Og=; b=x2CCbSIloVaGlujwpjDbF/uMxZ7ZNazdXdIeSAMT6YZAEou+fhGC+B20j3eHzOWovs ADkw7ol5+dMCWhY779RTZVD1t6Rf+S5auNfzoJl4WUN80KlfcqZkDH6n6Q8SQ0lERDGP F5To6AIYhkKb9LJZPepJ34josU6iawIf/tbMQowSBHLA0EoC0xgjOBWp4RwGfIEkuRuB tMr1Ors7+1eU6MJ8h5voTiOlVZ8VkKTyw0K6xYHsTgnbfs9IEyUI1+1pDjILjP65bdu6 vXf09fDBAZbIEBnOPCOR7s0O9A9cj1FwLtHwxPyfHnIqp6yX3IN70PXwPXUNWaUycdae eQ/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jMyx3sBU; 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-121418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121418-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bo17-20020a170906d05100b00a46be5169ecsi4777683ejb.511.2024.03.27.08.03.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:03:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jMyx3sBU; 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-121418-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121418-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 A0F0D1F32F55 for ; Wed, 27 Mar 2024 15:02:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BBD614532A; Wed, 27 Mar 2024 14:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jMyx3sBU" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) (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 A97E71448FF; Wed, 27 Mar 2024 14:23:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711549397; cv=none; b=aHZHEC2dbVSjbAxddz4g3Are8JiLllCWm1sJLwr/ZAxxya9dXJy0LoTy8mB1B4SJE+JY59JA+HtczCiIQxOxAmqm4LbT3TG3EcT0HLtCwh9nq6hz7lE9iWb+6CoGLx9ayUydHRD4yELAjK47vXzhvXLd7W2QpXtzXr+vY9zuB1g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711549397; c=relaxed/simple; bh=7vqygDDKbWmFw/FAY/rPhdZQEFODtjXCpRmC6ygQulQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zzvbu23N0vj1ecdbwKZrIfp0VgApki4/kILa8Ah0cjTA/kaALx6pzzW8+liThIrkpAjvHa4AWd6g4Z4tr24ueOqEojc6D6nhNhY2JYX5Ybi9vZqNwxuVqHJx5CLuG5U2dPNRmoe8SC4Xi5OvlOI+zNWCM6jBLVrPUeOeILtQsLM= 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=jMyx3sBU; arc=none smtp.client-ip=198.175.65.21 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=1711549395; x=1743085395; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7vqygDDKbWmFw/FAY/rPhdZQEFODtjXCpRmC6ygQulQ=; b=jMyx3sBU9+wa9TizPmIWAx2j3/sJ3hR3notAmROrGsB0dcaGE7Z3+Kcy +jjS67LkwiOe0ICP/Dsvnkpm71s42rRLA1EGshIuXs/WvUdNifgGhinHI xriB5pNQjlYDs5CB8Fr+rmZxDzqPdumsFMtVfz6sQM8r+nQ3Ng/SKPxCR PnjVT7JrLZu74RYoXdw5TO2eMUowpoFf04ZzynFOG69+P3gV8u+Zw9AQ9 9GzbdfCgX0liwhIds75i47+PliAK+oW7f6bfBMvaFqonxqjxosBb8p0Rp yp0ns7s+ZljzelUFDfPXuiK/y59bcTeH+dDYkCsY3nJckPN93Phk4uTnj A==; X-CSE-ConnectionGUID: OuZOBmLZSu+B6t2qrgE3oQ== X-CSE-MsgGUID: UNFEn9dWR5GgMcWDXYIkTw== X-IronPort-AV: E=McAfee;i="6600,9927,11026"; a="6592530" X-IronPort-AV: E=Sophos;i="6.07,159,1708416000"; d="scan'208";a="6592530" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2024 07:23:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,159,1708416000"; d="scan'208";a="20973064" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmviesa004.fm.intel.com with ESMTP; 27 Mar 2024 07:23:13 -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 v2 1/3] compiler_types: add Endianness-dependent __counted_by_{le,be} Date: Wed, 27 Mar 2024 15:22:39 +0100 Message-ID: <20240327142241.1745989-2-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327142241.1745989-1-aleksander.lobakin@intel.com> References: <20240327142241.1745989-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 Acked-by: Gustavo A. R. Silva 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