From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 A6A9F298CB2 for ; Sat, 20 Jun 2026 09:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781948876; cv=none; b=o7IwM4zKCvnabF4injTmq/34Oa1ET/IsDzRC5VpJ0KOofXnsOXKyCrVPjwcMHdaYn3jKIvh1tn53pg5evRwo54Dunjzj+AnLBQsLYK7W35wA6jriu2jdpA7tqZpYjjX1LRwHf9UUWTSON1SX9Bi/oDkA6aaIlU6kUb9oakqBGeE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781948876; c=relaxed/simple; bh=JROjnkSJB1U4ePqKZpqgur7TGgaHRduatsqZY6QLSXQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ef43eVKzriCbXe0LRvO8qVyDjD+PmwcaW8TcVsPg4s9FigaUjhqR0sYsZp483Zn5CszE9Qr9w3vjAk/wkwMSQkWeymAXE8hI2gpyyC0MbDTg42T1Vthq5JBS3K6Cu0aThWMUJh9rqlArEhUyCPWJoc+6pY0hul7DvWSTl65qCmk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TFM5gac8; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TFM5gac8" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-490b9318997so19593915e9.2 for ; Sat, 20 Jun 2026 02:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781948873; x=1782553673; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=FSYbUXTd9Ngne4Xxtlx29c5BFb1lGxLtQTLGucvyu0A=; b=TFM5gac8+4/nFSGFsuIRgp0qMJADu8yVC/P86bf3yF66Kgv7gx3DBj0aXcio16fSjm QHdInK3tjJo+LngGnd+dbLyPYw5eRltT1cn6MaiGLE2qpUDHlvp5yWomb8eratdaYXUG F6zXhKY0hr7AgXITIul2oprC9onDZeRHIutd7xS9QbHuCZ8+/1Cf1UIz7wNF/Y5SoNj8 xbKZr6U9jK8WFOETJS5jQKh6KkBc02YMrgnR5NbrjR8c7IMxjcTdvnQfNq0BdO46qSr2 NnYEEy2TRWEsVl0jJ4UupulKtLcdAWjmowSqMhQPsZlRHrW7/GSZdyHxThjeQdzkwHjk uAsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781948873; x=1782553673; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=FSYbUXTd9Ngne4Xxtlx29c5BFb1lGxLtQTLGucvyu0A=; b=eNgF5nrqbYDlYlrUmQ6kTtEfN6CZP7COjq5lZw/DTlsmj4ERvaE7/0KjHeaIoFkAHt Tt2cl2xk6/xo8UD6PimoRCC7614SiCxAuGzMqT7dO9fytiOy64uawq6bn0oTU0Nt1O1l mCcnkom38d9mkIx2qpGY33lvcH0OXTSFbsej9iQmL21wi4iibcjMBGxj4kZbr5xmpS/M kIh05XK8qmQCLOy6moqMUL+nOn+sZM4OQZ+pA9rdFwvusGR8TrskY9eFJiFjnMorA9QW hjlOg1FItnwmLzISPzJJ/fdxBjEeiUA5q1fxC6K85nncaP0nOaAizfi/0thf1HW9sRQM IPSA== X-Forwarded-Encrypted: i=1; AFNElJ/b6xKPTfrRfvIcn9Z0oA6pzPEntq8UrBL7mVavQaEyFdia7jkkgRZNLNIwbTWP2ivXgfo+tnWcQuHD+Mw=@vger.kernel.org X-Gm-Message-State: AOJu0YwX76dWXqkkhptXJOUQHMgUGznqWatMZkPrGMC0jBxIn6SKJKrv SXJpVqrsoQWhSkQv6gobY7OsOqIks4tiDPMwYVIKnJXk327v4VlXqlD5 X-Gm-Gg: AfdE7cnDA2/xxsO6uRzcCv5wjYnCBf+s9iavphWjQgcaRkfLiUChElOyiGtqLTPRa4u Os0VqxOg+m5+xkRWFlpGBfGsU1GZfeqv3WbhsKeknVZICqOnNN4Lb286wBM9qSAthpsIjI+s3XT wf4ZTBkSF4PRuWmG+PAcZgrxysksIeAFnt34JEppInn7OYmA1lpLM7JQ4Y5OyDvgkNbp4BaCewQ TvR+489DwF2agwoQECtjnk/sdW80u54UdyVKu1gqMm8m52yKmb1Jva+a/CLq5BKTWQTO4xhCw3A 0OijdqSniJ0Ex8IVFdRZf5SgMiooUIO4ZspSD+FcPmeneGlvA8uX9lgz6fTkyWsOtxO8NndoRG6 2nDnw0fWSKqBNgVX/fGKDf/Itkp5B9VSSIORyL13EpOE7uen8uYCPYnpi9lhubJOwrtnNcEMZBI NAWkeALolVujKUo63kg8EMkhMYJzHV4PniG9fE9lUNiiZOhE79mQ+Ywi81Kjt+ X-Received: by 2002:a05:600c:8b42:b0:490:b724:5085 with SMTP id 5b1f17b1804b1-4923f5944eemr141374365e9.33.1781948872931; Sat, 20 Jun 2026 02:47:52 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49240f054e3sm125314975e9.2.2026.06.20.02.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jun 2026 02:47:52 -0700 (PDT) Date: Sat, 20 Jun 2026 10:47:50 +0100 From: David Laight To: Runyu Xiao Cc: Taras Chornyi , netdev@vger.kernel.org, Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Oleksandr Mazur , Andrii Savka , Vadym Kochan , Volodymyr Mytnyk , linux-kernel@vger.kernel.org, Jianhao Xu , stable@vger.kernel.org Subject: Re: [PATCH net] net: marvell: prestera: use unaligned accessors for DSA tag Message-ID: <20260620104750.5270a11c@pumpkin> In-Reply-To: <20260620093739.2164921-1-runyu.xiao@seu.edu.cn> References: <20260620093739.2164921-1-runyu.xiao@seu.edu.cn> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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-Transfer-Encoding: 7bit On Sat, 20 Jun 2026 17:37:39 +0800 Runyu Xiao wrote: > Prestera parses and builds its 16-byte DSA tag from an skb byte buffer. > The current code casts the tag pointer to __be32 * and then reads or > writes the four tag words through that typed pointer. > > The tag pointer is derived from skb data, but that only identifies the > protocol tag location inside the packet buffer. It does not make the tag > a naturally aligned __be32 array. Use the unaligned big-endian helpers > for both parsing and building the tag. > > This issue was detected by our static analysis tool and confirmed by > manual audit. The same access pattern was validated with UBSAN alignment > instrumentation by keeping the original cast from a u8 DSA tag buffer to > __be32 * and reading dsa_words[i] from a deliberately misaligned tag > buffer. UBSAN reported misaligned-access loads of type '__be32' in > prestera_dsa_parse(). > > The driver has the same source-level issue: the RX path parses bytes at > skb->data - ETH_TLEN, and the TX path writes the tag at skb->data + > 2 * ETH_ALEN. Those offsets identify the DSA tag bytes, but they do not > establish a __be32 object or a 4-byte alignment guarantee for typed loads > and stores. Stop sending these 'fixes' unless you can do proper analysis. skb data is guaranteed to be aligned so that these reads (and ones of the IP/TCP/UDP headers) are aligned. David > > Fixes: 501ef3066c89 ("net: marvell: prestera: Add driver for Prestera family ASIC devices") > Cc: stable@vger.kernel.org > Signed-off-by: Runyu Xiao > --- > .../ethernet/marvell/prestera/prestera_dsa.c | 19 +++++++++---------- > 1 file changed, 9 insertions(+), 10 deletions(-) > > diff --git a/drivers/net/ethernet/marvell/prestera/prestera_dsa.c b/drivers/net/ethernet/marvell/prestera/prestera_dsa.c > index b7e89c0ca5c0..276f98cbd50e 100644 > --- a/drivers/net/ethernet/marvell/prestera/prestera_dsa.c > +++ b/drivers/net/ethernet/marvell/prestera/prestera_dsa.c > @@ -4,6 +4,7 @@ > #include > #include > #include > +#include > #include > > #include "prestera_dsa.h" > @@ -33,15 +34,14 @@ > > int prestera_dsa_parse(struct prestera_dsa *dsa, const u8 *dsa_buf) > { > - __be32 *dsa_words = (__be32 *)dsa_buf; > enum prestera_dsa_cmd cmd; > u32 words[4]; > u32 field; > > - words[0] = ntohl(dsa_words[0]); > - words[1] = ntohl(dsa_words[1]); > - words[2] = ntohl(dsa_words[2]); > - words[3] = ntohl(dsa_words[3]); > + words[0] = get_unaligned_be32(dsa_buf); > + words[1] = get_unaligned_be32(dsa_buf + 4); > + words[2] = get_unaligned_be32(dsa_buf + 8); > + words[3] = get_unaligned_be32(dsa_buf + 12); > > /* set the common parameters */ > cmd = (enum prestera_dsa_cmd)FIELD_GET(PRESTERA_DSA_W0_CMD, words[0]); > @@ -82,7 +82,6 @@ int prestera_dsa_parse(struct prestera_dsa *dsa, const u8 *dsa_buf) > > int prestera_dsa_build(const struct prestera_dsa *dsa, u8 *dsa_buf) > { > - __be32 *dsa_words = (__be32 *)dsa_buf; > u32 dev_num = dsa->hw_dev_num; > u32 words[4] = { 0 }; > > @@ -98,10 +97,10 @@ int prestera_dsa_build(const struct prestera_dsa *dsa, u8 *dsa_buf) > words[1] |= FIELD_PREP(PRESTERA_DSA_W1_EXT_BIT, 1); > words[2] |= FIELD_PREP(PRESTERA_DSA_W2_EXT_BIT, 1); > > - dsa_words[0] = htonl(words[0]); > - dsa_words[1] = htonl(words[1]); > - dsa_words[2] = htonl(words[2]); > - dsa_words[3] = htonl(words[3]); > + put_unaligned_be32(words[0], dsa_buf); > + put_unaligned_be32(words[1], dsa_buf + 4); > + put_unaligned_be32(words[2], dsa_buf + 8); > + put_unaligned_be32(words[3], dsa_buf + 12); > > return 0; > }