From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 87D5A2DCF74 for ; Tue, 24 Feb 2026 23:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771974403; cv=none; b=JevxGjMddoZqXurve7nxqNYvE/ZSo08996u3osYYXOM7QyZu9/Ois2PW0Kf+a0iXf7rv6WijfCMxHpqScpymrUizLko+jCXqoUtYODaKL2WA6AygKzFZlS4GV+nr2Cfq4Aj4hTH8NOnbc5x/rPIZECo4orLZ7YKSUsmKMgKKlEw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771974403; c=relaxed/simple; bh=A4LHSP/FTFWxupGlq1bnECf6E6hsobcTrNUS0LVBR2o=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u8mPXOa9Y3uRrfX2znlAXMjjLEwhH5M/dT3xAKpHGhFZUecmhHvAHu80eE1K2vasU9RQekKHTnyWiU5mIQYzRHS0HxKCKEzsDcEALBB9CT8eM8VVjS5Qbyb5huSF/8yS/cg6qJcUzgeLpzdGUNT6uFBmWv8/5cQCKWE313fXq+E= 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=AFm1o69M; arc=none smtp.client-ip=209.85.128.46 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="AFm1o69M" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-48334ee0aeaso45788415e9.1 for ; Tue, 24 Feb 2026 15:06:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771974399; x=1772579199; 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=+8rwrn/QPCZdFh+0pKkte8IyiM/p1Y0Q9LAts5L8c8k=; b=AFm1o69Mid/FOsat4an1aG0KD/keq+BRfUZBe2sdC3UrDcyvGf/TYSnsFvPfF1ulgJ 7TF9sR/nX09ZUWmO2vsXR6d+vEngHt66TgyKGZOUuTr7dd49E7OeoxPeUUwg2iAqFapm BiESq9Wp5uY8zMLShf+gjNXkxkIj0EutmpSYWSp7ouaTx3CpJEgyyRb/UQyhYvrNnhrK KvG9RWCoWtNflxzfBR/w6A80hA7YnGz6I0hG5Y+SIUJ9dn+OuOcZQf+RsLoA/7vUdWUE O0s5UEVQ4pVoHGtTQwYvJj9j2fv5/cN7H5/8Ua9ZCYu9n1imVigqV2OGNz/OGeM9FQ4w vYkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771974399; x=1772579199; 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=+8rwrn/QPCZdFh+0pKkte8IyiM/p1Y0Q9LAts5L8c8k=; b=LZ8nt2bEcszfbYfaL6485M02AVzDktyOp4yit6AfELAFNK6BYUa5SS9wpIshnYiHLy ObZJrRjuhtceU5dk5KJiR8pNzXpPiGGCa3sdQiAVjinnZkxT3R4sZ5dsYBwGm6FfouZg A8FFOAKIwZA4sPWmF2x6Y/p/Iivtg6ndhGyza/5s8t38QagJA6CqB/2YJW+2o57GsaGl pM9tF/X58NUS0jwwPB17Ax8mrXKRkvWMLQ/DH+19QuhS8s97/7gZxdVA2vzTTjvwO9+O Q0/0TNdEtQJpxe7ma78CHt1NVYksw+uZUguSAq5cqeKJI1PwtnBObMA6yGFRpxWNGHOt PQ+w== X-Forwarded-Encrypted: i=1; AJvYcCUJyeuhxqlUIkAoIhjaNvOot3WwuRvcHVuTm8w6MkxFIkxy+CZ9zHwaOMB07/XvXUfZJ4JGxk1hdWTMx/Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yymxd1LsojEPHzGppmEnL64hZNH4kmxWpZOUGNWzYtrvi8B/Iox fxb1gN3E/OmaQgx7tkklQouRxi4Uc31K14Ry1qfrP/nQ3ApFN1whwBQ/7Pn/+xMb X-Gm-Gg: ATEYQzzuuh52klgO+/3MIqhrGGmZP6KpdsYrF7zzUDTwGVGtuoOPB2f5PYQh0dW0vhe vGI+J+jOolRQ1KaHN0UwVB17dAXfXyiY38OolNNVws2qT346nJPP162QDKeDwd+cBfsQZDcLhJb P7QPraKLVU7ZaMicEzfby7yK7RzCO7NpFr0y54FNew635LitVnZRy/VT9HYeylASniOdbfLMl9H WQgCEp1Ugjp0lHY4TOwjCEExqQe0+uIUXhBJZY50gF/SFbTihvkngsIwsKW1IxImrRXjMU8Pvxp tYWT6PGX4qlnd93VHT+vrdXenzSxen4w+jJQDDwfUq4JOhNWIfT81vw5euBSzZifz6GAScsbQiS OMfSiXaxpKv4V6QI0+JJGQIOoPMePuEj6EKhGUNOTvDAGRIy7fDn6yb/ty5BZSn7AxSmQKO+rHo fUMAFNmnj8M7Lviy6Q2dQljZwUHdiLOB+z8SU4YmV8bPtfErfkYXbeOhrgbti3zbYySeHYMP5ok p8= X-Received: by 2002:a05:600c:8b02:b0:477:7ab8:aba with SMTP id 5b1f17b1804b1-483a95aa31dmr234688615e9.1.1771974399425; Tue, 24 Feb 2026 15:06:39 -0800 (PST) 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-483bd6854c7sm86477705e9.0.2026.02.24.15.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 15:06:39 -0800 (PST) Date: Tue, 24 Feb 2026 23:06:37 +0000 From: David Laight To: Fuad Tabba Cc: Andy Shevchenko , Kees Cook , Andy Shevchenko , Andrew Morton , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, will@kernel.org Subject: Re: [PATCH] lib/string: Fix UBSAN misaligned access in sized_strscpy Message-ID: <20260224230637.38f93836@pumpkin> In-Reply-To: References: <20260224170427.2296592-1-tabba@google.com> 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 Tue, 24 Feb 2026 17:54:07 +0000 Fuad Tabba wrote: > Hi Andy, > > On Tue, 24 Feb 2026 at 17:21, Andy Shevchenko > wrote: > > > > On Tue, Feb 24, 2026 at 05:04:27PM +0000, Fuad Tabba wrote: > > > sized_strscpy() performs word-at-a-time writes to the destination > > > buffer. If the destination buffer is not aligned to unsigned long, > > > direct assignment causes UBSAN misaligned-access errors. > > > > > > Use put_unaligned() to safely write the words to the destination. > > > > Have you measured the performance impact? > > Not directly. I verified the disassembly for both x86_64 and aarch64. > On x86_64, both the raw pointer cast and put_unaligned() compile down > to mov %rdi,(%rsi). On aarch64, both compile to str x0, [x1]. What happens on cpu that trap misaligned accesses (eg sparc64)? put_unaligned() exists because it can be horrid. David > > > Have you read the comment near to > > > > if (IS_ENABLED(CONFIG_KMSAN)) > > Not until now to be honest. However, are you asking whether > put_unaligned() breaks KMSAN? I don't think it does, max is set to 0 > when KMSAN is enabled, this entire while loop is bypassed. > > Thanks, > /fuad > > > ? > > > > -- > > With Best Regards, > > Andy Shevchenko > > > > >