Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp100029rdb; Wed, 14 Feb 2024 14:09:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVfcrq/SXUkQFUaTq4CH3MCxxsgflciHQUlCTQa1Ie66BbfB0PhmhJiAozVGmosi5b2Pp3lpTiF7TGY3fQywRNIV0FoXnSBlynmk+a0Ng== X-Google-Smtp-Source: AGHT+IHHcGCvTjJdFhcbBgLhZTVZP+tNEDPYXP9cLWo1kXUKLoeAoP1Jrzor5yCxN44TxcN9VADA X-Received: by 2002:a05:6808:305:b0:3bf:e742:d57b with SMTP id i5-20020a056808030500b003bfe742d57bmr128136oie.19.1707948584127; Wed, 14 Feb 2024 14:09:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707948584; cv=pass; d=google.com; s=arc-20160816; b=UzvrOYDTTVsVuSwPTgZlvBWxvyNtTZZufS4sbEqZsMD2r+wwWCDSkppQ2uOBa4HOHd G6qqlXoskuWnQlMjYZVdEIWl2WQhuqhUE8LherE8aGJvhUEYRG6c3hno2kh+b0n20xpC G83eoSRCP7g0lsElFTBpuxn3Zt+NOKuHrBqxjJ3Qr4GcdcKVYlUX7EA5Oxyhv8UcSV2e GeyfGC0i3Xj3h3eI0bUpnFWWO+sASBs7q0cghXjbNjaJ2WQtC85fNeArnjrexTbjT1Ao Jps7C03W50OYgnCMVJYqxM2+nJku3XQQ7qq0400AvLii5QRTilnoI64Z4eU4vkVd7hxP fcHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UKC90cK1z5oF1gcZg9hwRMmNU2RFG8t/vNnGjpX63Tw=; fh=V7vvrnGeDe5NFuaq0OTHvbyZChKCE2aaPpimzN3pyyI=; b=VBvSlJnTC0mWZcXXz/OpNwvjHchRL/jWyDrxex48P5f2E5K1kWRua2ZX1Tit3o8m21 JlmFRRf6m15lqaRJjnQI86jJSEpC9XHpQ+l8r4WkFiEsR0TnSByYyL+OpJbkMIzh6rr7 HR/9Q/01fsRusKfQOTyh+1f03lmhoPrc/Zm5sUTn2aoXz580kkr6gonpYLjVCVqBjtF9 coWL8p45VerTO10z8SqoUhTFMJa2gzH+sTCzP9GlPev6AiFi+DhuF2hKVf36lf2Tm+js n2Cjgn2OW3ouaNx0DtfH/Oas3WvbvpAm42kYGRatT/hxOX0PUMPTSN74y/F9cKUk1K/5 DkhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VWWp+3yv; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-66029-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66029-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org X-Forwarded-Encrypted: i=2; AJvYcCV7KXaDDlsk4zRJLaAiDfYn52b8mMElXGIVqZ44n5cDbm3vK9ZCmEuPrObZS3vp18RGaZuBVcoIwEiYr0gumVDrqyv4nw3fEmJuf2EL0A== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h10-20020ac846ca000000b0042c629b055bsi5971392qto.709.2024.02.14.14.09.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 14:09:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66029-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VWWp+3yv; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-66029-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66029-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BD2621C21DC4 for ; Wed, 14 Feb 2024 22:09:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F41DE14198F; Wed, 14 Feb 2024 22:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VWWp+3yv" Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA3C91DDF1 for ; Wed, 14 Feb 2024 22:09:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707948577; cv=none; b=QqPOGQG+THYTZ2kkNfvdJqre6cHq2JIIvkVdWk45WlJoS4lYesKMvKjN5RUcNIeKLoFNU5Gid1qh8slGTPXIdROCVlyTm7ZQ/q+0qNbwjJcZAAGCLTR1ptidapl9tJejgIEtkt0MN13E1VubnnTJ1pr8ObWWSz4g4+IT6o73kD8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707948577; c=relaxed/simple; bh=VTAmMg+BgFLnXnjh2RFbOxx2A7QCbkF4jCDwOsg/fb8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jIZt+8BHj/mZrKtqFYKGr1tx0QamFbDX+nW38Eqpht4kzTDbngx2CIJ/cYcHyCSJVWeX64xThHKSI4MjFBc8XEOYjtj43TZUsHVv2cUgiWLxmt2xBTYsVOCPlSUg5EbjzRkQ1zcCoRZVdbcHelHsc7c1ztQtCnk7XhztTFnnBO4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=VWWp+3yv; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-298fe09f851so29816a91.2 for ; Wed, 14 Feb 2024 14:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707948575; x=1708553375; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=UKC90cK1z5oF1gcZg9hwRMmNU2RFG8t/vNnGjpX63Tw=; b=VWWp+3yv7CVu4Ichuui2QgsbyitfZhwzs4yUF31iOb6W9cV+Zf5P83zejS5AzEhHsX cDf+hgBQSi5BkgRRgsu3523uDnm0vY1PcoqYPBUcI3X36/BmdeUsrJRWQPwOcG2+fFhq GQ6qsGltSotZho7dChjqnPcBLS0VJ6h+K2zQw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707948575; x=1708553375; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UKC90cK1z5oF1gcZg9hwRMmNU2RFG8t/vNnGjpX63Tw=; b=YZ0cBD3ocqSCTDtlcqwDYQJEZ68pna5+eA7CCryhzlZgjSaprxbs71nnqNI50ZVwyr hHU36qmZk6gfL9DBDTnu7s29lj+adYAU8v3jJ68vMiWRfyMw08PK3kYumRB22ddk2noL 9RM6cwuB1jAsiiDLTjFR5bc2J/sEFezOjXp54CM2bS1j/Wy4N5+3I5J+qdNZXfdyXpb8 OgkCn0zPQdN/fZ4+E1VZNK+2c+sqx/4RDLS2gpGrIai+V0BtKGx2nJ8GKa6u//HNJejn XuS9tDUg8k86dLpv2QWy70lHODxb3/vHv4GWU43wZceNUXnMhK53Gl9FQNgRJlihwdiM o37Q== X-Gm-Message-State: AOJu0Yx9yCL/eq4wyA7wl4Fyj3sYY4eZNZLGaCgcbB8ddu58wASZtrrl JkoAv/yA0WwT9CQBBCUWoyQ8uHMW5YIwxEUnnaNVHMF916R3qgOxWesHJ7YO+A== X-Received: by 2002:a17:90a:ce08:b0:295:ff5d:cb1d with SMTP id f8-20020a17090ace0800b00295ff5dcb1dmr47666pju.4.1707948575070; Wed, 14 Feb 2024 14:09:35 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id e4-20020a17090a728400b00297022db05dsm1872088pjg.40.2024.02.14.14.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 14:09:34 -0800 (PST) Date: Wed, 14 Feb 2024 14:09:34 -0800 From: Kees Cook To: Michal Wajdeczko Cc: linux-kernel@vger.kernel.org, Andy Shevchenko , Alexey Dobriyan , Jani Nikula Subject: Re: [PATCH 1/2] wordpart.h: Helpers for making u16/u32/u64 values Message-ID: <202402141408.0E78D47@keescook> References: <20240214214654.1700-1-michal.wajdeczko@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240214214654.1700-1-michal.wajdeczko@intel.com> On Wed, Feb 14, 2024 at 10:46:53PM +0100, Michal Wajdeczko wrote: > It is quite common practice to make u16, u32 or u64 values from > smaller words. Add simple helpers for that. > > Signed-off-by: Michal Wajdeczko > --- > v2: new macro names due to conflict with crypto/aria.h > explicit cast and truncation everywhere (Alexey) > moved to wordpart.h (Andy) > --- > Cc: Kees Cook > Cc: Andy Shevchenko > Cc: Alexey Dobriyan > Cc: Jani Nikula > --- > include/linux/wordpart.h | 32 ++++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/include/linux/wordpart.h b/include/linux/wordpart.h > index f6f8f83b15b0..8c75a5355112 100644 > --- a/include/linux/wordpart.h > +++ b/include/linux/wordpart.h > @@ -31,6 +31,38 @@ > */ > #define lower_16_bits(n) ((u16)((n) & 0xffff)) > > +/** > + * make_u16_from_u8 - make u16 value from two u8 values > + * @hi: value representing upper 8 bits > + * @lo: value representing lower 8 bits > + */ > +#define make_u16_from_u8(hi, lo) ((u16)((u16)(u8)(hi) << 8 | (u8)(lo))) Do we want to actually do type validation here? Right now it's just cast/truncating, which based on the version log is by design. Is silent truncation the right thing to do? -- Kees Cook