From nobody Tue Dec 2 02:52:29 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 98C7C2F5337; Mon, 17 Nov 2025 16:50:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763398237; cv=none; b=Id1ScwIVkpxTWkCTN7w0u+DnodoosTrm9wemE8VXIhpSB0gH1s8T422uaOMXNlqoewobMLNIJUNILRsB+hjoW0rt5EyJd0Eiks9jgyaG+9ZUua2B38VQqGm5FcFnTYvy6tOA+ieJqwCVZJ2HxoaRvS2fjy3911xFHLjRh9vQjDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763398237; c=relaxed/simple; bh=rLnSkle9gDtzmk+Xzjh4JTt9WyaHRuH0dl6amNgDsgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tbz2OI1UwV+wr/s/2xE4aIN+PfcX382okON4ZNviSBjty2K9NnaDtObGnBXiiuSSgGJH+tASVTdEnVMnPYqW0HP1v6qEbk51WMsQlLlK3L0twoXGFyvZcy0bM89+s/cvsg3Jh5E6ZyxBrbYSSX+sVBNuSixVj5KOogOzJHhbFxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub4.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4d9D964M8Rz9sTQ; Mon, 17 Nov 2025 17:44:10 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3rt6ikktw9sm; Mon, 17 Nov 2025 17:44:10 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4d9D9638tnz9sSL; Mon, 17 Nov 2025 17:44:10 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 540BA8B763; Mon, 17 Nov 2025 17:44:10 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 7sNQuGfP_LfF; Mon, 17 Nov 2025 17:44:10 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.235.99]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 347AE8B768; Mon, 17 Nov 2025 17:44:09 +0100 (CET) From: Christophe Leroy To: Thomas Gleixner , Peter Zijlstra Cc: Christophe Leroy , Alexander Viro , Christian Brauner , Jan Kara , Ingo Molnar , Darren Hart , Davidlohr Bueso , "Andre Almeida" , Andrew Morton , Eric Dumazet , Kuniyuki Iwashima , Paolo Abeni , Willem de Bruijn , "David S. Miller" , Jakub Kicinski , Simon Horman , Daniel Borkmann , Dave Hansen , Madhavan Srinivasan , Michael Ellerman , Nichlas Piggin , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v5 1/4] iov_iter: Convert copy_from_user_iter() to masked user access Date: Mon, 17 Nov 2025 17:43:41 +0100 Message-ID: <58e4b07d469ca68a2b9477fe2c1ccc8a44cef131.1763396724.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1538; i=christophe.leroy@csgroup.eu; h=from:subject:message-id; bh=rLnSkle9gDtzmk+Xzjh4JTt9WyaHRuH0dl6amNgDsgk=; b=owGbwMvMwCV2d0KB2p7V54MZT6slMWRKBxw/U/rkPt+bqXsso2+trmi+bHKls0f76bOjvtFBu 98d1L33qqOUhUGMi0FWTJHl+H/uXTO6vqTmT92lDzOHlQlkCAMXpwBMRHkWI8Oc5nubJl3hm2vk sPjTg6ONon2q7p5t0otnK8VZd6aoO8kxMswMeGirabeizWPDTi6RbW2bzzgkp/nacr7ST90TKce xiwsA X-Developer-Key: i=christophe.leroy@csgroup.eu; a=openpgp; fpr=10FFE6F8B390DE17ACC2632368A92FEB01B8DD78 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Following patch will add missing barrier_nospec() to copy_from_user_iter(). On some architecture like x86 it might degrade performance, which would be unfortunate as copy_from_user_iter() is a critical function. Convert copy_from_user_iter() to using masked user access on architecture that support it. This is similar to what was done for copy_from_user() by commit 0fc810ae3ae1 ("x86/uaccess: Avoid barrier_nospec() in 64-bit copy_from_user()") Signed-off-by: Christophe Leroy --- v5: Changed commit message v2: New in v2 --- lib/iov_iter.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 2fe66a6b8789..a589935bf302 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -49,12 +49,16 @@ size_t copy_from_user_iter(void __user *iter_from, size= _t progress, =20 if (should_fail_usercopy()) return len; - if (access_ok(iter_from, len)) { - to +=3D progress; - instrument_copy_from_user_before(to, iter_from, len); - res =3D raw_copy_from_user(to, iter_from, len); - instrument_copy_from_user_after(to, iter_from, len, res); - } + if (can_do_masked_user_access()) + iter_from =3D mask_user_address(iter_from); + else if (!access_ok(iter_from, len)) + return res; + + to +=3D progress; + instrument_copy_from_user_before(to, iter_from, len); + res =3D raw_copy_from_user(to, iter_from, len); + instrument_copy_from_user_after(to, iter_from, len, res); + return res; } =20 --=20 2.49.0 From nobody Tue Dec 2 02:52:29 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 42AB22FC034; Mon, 17 Nov 2025 16:50:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763398242; cv=none; b=ByIAWEh54/uBdYkkfyF2QjR8dfz7Q3/MEr0CYoo9HToaqf2qq89frCUUNJPImqqiXN8RE3rJYctkuqocqYgN/pbAeZGpw4NPJVFBBXBb8F+Y/1UOx5P3Kqq87XZG/8r+ybw52wdJnfHY7RXeB0wFCTX8LZTY+cBixyHECl8SqdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763398242; c=relaxed/simple; bh=MaSZLcG93ruseoCd/jNUTCbVIjzk2wIX1qL4RQMUeN0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GU4nQqBdQPWpBpxjdQAcH9uMALEH3YHgfm/wDXr+VoZw2JNVHQvdAIci4LZaZOWnSVZ9xWmuWAGbVmX7zeU/UHkvecY0GEiH1cBDWYueqRKWjlJyukZ1onl2ypesvyQx6QQJYNabpqscBfcZTyukGYM7ZsimuRqYs19Q5oKB/9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub4.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4d9D974sv3z9sTX; Mon, 17 Nov 2025 17:44:11 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B6EAP4w0AuZ2; Mon, 17 Nov 2025 17:44:11 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4d9D9746V2z9sTW; Mon, 17 Nov 2025 17:44:11 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7A3DB8B763; Mon, 17 Nov 2025 17:44:11 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id Zrq7Eiq6nOLm; Mon, 17 Nov 2025 17:44:11 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.235.99]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5B6B38B769; Mon, 17 Nov 2025 17:44:10 +0100 (CET) From: Christophe Leroy To: Thomas Gleixner , Peter Zijlstra Cc: Christophe Leroy , Alexander Viro , Christian Brauner , Jan Kara , Ingo Molnar , Darren Hart , Davidlohr Bueso , "Andre Almeida" , Andrew Morton , Eric Dumazet , Kuniyuki Iwashima , Paolo Abeni , Willem de Bruijn , "David S. Miller" , Jakub Kicinski , Simon Horman , Daniel Borkmann , Dave Hansen , Madhavan Srinivasan , Michael Ellerman , Nichlas Piggin , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v5 2/4] iov_iter: Add missing speculation barrier to copy_from_user_iter() Date: Mon, 17 Nov 2025 17:43:42 +0100 Message-ID: <6b73e69cc7168c89df4eab0a216e3ed4cca36b0a.1763396724.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1316; i=christophe.leroy@csgroup.eu; h=from:subject:message-id; bh=MaSZLcG93ruseoCd/jNUTCbVIjzk2wIX1qL4RQMUeN0=; b=owGbwMvMwCV2d0KB2p7V54MZT6slMWRKBxxX3PAkbObONVNX3ny3/Sr7tYkJtiXP+/xeFZ6wT ci7otS9oKOUhUGMi0FWTJHl+H/uXTO6vqTmT92lDzOHlQlkCAMXpwBMZJIJI8OtiC+XXkppPlyz unjhqRuqTEJbclpcf0v4Mk9jVDn16CcPw39fsW351z703dcMY7zu8bBnxoQrN5ktpzYci38SzXv 9qTk/AA== X-Developer-Key: i=christophe.leroy@csgroup.eu; a=openpgp; fpr=10FFE6F8B390DE17ACC2632368A92FEB01B8DD78 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The results of "access_ok()" can be mis-speculated. The result is that you can end speculatively: if (access_ok(from, size)) // Right here For the same reason as done in copy_from_user() by commit 74e19ef0ff80 ("uaccess: Add speculation barrier to copy_from_user()"), add a speculation barrier to copy_from_user_iter(). Signed-off-by: Christophe Leroy --- lib/iov_iter.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index a589935bf302..896760bad455 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -49,11 +49,19 @@ size_t copy_from_user_iter(void __user *iter_from, size= _t progress, =20 if (should_fail_usercopy()) return len; - if (can_do_masked_user_access()) + if (can_do_masked_user_access()) { iter_from =3D mask_user_address(iter_from); - else if (!access_ok(iter_from, len)) - return res; + } else { + if (!access_ok(iter_from, len)) + return res; =20 + /* + * Ensure that bad access_ok() speculation will not + * lead to nasty side effects *after* the copy is + * finished: + */ + barrier_nospec(); + } to +=3D progress; instrument_copy_from_user_before(to, iter_from, len); res =3D raw_copy_from_user(to, iter_from, len); --=20 2.49.0 From nobody Tue Dec 2 02:52:29 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 936A62FBDEE; Mon, 17 Nov 2025 16:50:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763398251; cv=none; b=fJeUHEOlwO5yXRrKDLnAsUy6FWWRTN1WAHEaeA3zbFzDcaftSXBPxGwqs/EQ77I11cN8SnR2uNGms92NZOjomuxtPrp3YfoYEA0s6kld6XPqqIsteRoEDCyZtimxewH/1PUSIg4hs/OCKmqjRLSOlj9xDZMRkUy6/t1MWZbRg8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763398251; c=relaxed/simple; bh=G9vSR7KnQqIxN+4o+okHL5tWkQyiUXlrPWVzKylp4RY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=faq947fRijeNANQ1bp8OZ4tVWOjK1ufkNcfgqMlRvla/0CbGcIrseY4Q2NTpjDIVocO577KMXJ+X+WYMwX3EvlU/+9yGkz37TVVbEMpgP6i2+YGo2gAxjDb4jQwMC3dWCFITOOG2uCkovzKwXH6s77FLoIMp0193d5JfZLtk3Fo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub4.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4d9D986Dcjz9sTh; Mon, 17 Nov 2025 17:44:12 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ODDw4OUpL3tH; Mon, 17 Nov 2025 17:44:12 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4d9D98579Gz9sTZ; Mon, 17 Nov 2025 17:44:12 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9D7F18B763; Mon, 17 Nov 2025 17:44:12 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id hO1787tWgDqo; Mon, 17 Nov 2025 17:44:12 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.235.99]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7FB1E8B768; Mon, 17 Nov 2025 17:44:11 +0100 (CET) From: Christophe Leroy To: Thomas Gleixner , Peter Zijlstra Cc: Christophe Leroy , Alexander Viro , Christian Brauner , Jan Kara , Ingo Molnar , Darren Hart , Davidlohr Bueso , "Andre Almeida" , Andrew Morton , Eric Dumazet , Kuniyuki Iwashima , Paolo Abeni , Willem de Bruijn , "David S. Miller" , Jakub Kicinski , Simon Horman , Daniel Borkmann , Dave Hansen , Madhavan Srinivasan , Michael Ellerman , Nichlas Piggin , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v5 3/4] scm: Convert put_cmsg() to scoped user access Date: Mon, 17 Nov 2025 17:43:43 +0100 Message-ID: <793219313f641eda09a892d06768d2837246bf9f.1763396724.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1623; i=christophe.leroy@csgroup.eu; h=from:subject:message-id; bh=G9vSR7KnQqIxN+4o+okHL5tWkQyiUXlrPWVzKylp4RY=; b=owGbwMvMwCV2d0KB2p7V54MZT6slMWRKB5y4msa79uMdnvb97Ws8Dr5sdLO50Ghlq90Ym1rzX Ofc1FTWjlIWBjEuBlkxRZbj/7l3zej6kpo/dZc+zBxWJpAhDFycAjARSyVGhpazbZ9+HNTk3i7v amJmo3boZihrUcvNMkv+VxX/Nl/4F8vI8EOU7U+KU0bAKSa/9293WU7XvRW190pY0r+tVmXBk7d a8wMA X-Developer-Key: i=christophe.leroy@csgroup.eu; a=openpgp; fpr=10FFE6F8B390DE17ACC2632368A92FEB01B8DD78 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the open coded implementation with the scoped user access guards. No functional change intended. Signed-off-by: Christophe Leroy --- v5: New --- net/core/scm.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/net/core/scm.c b/net/core/scm.c index 66eaee783e8b..cd87f66671aa 100644 --- a/net/core/scm.c +++ b/net/core/scm.c @@ -273,17 +273,13 @@ int put_cmsg(struct msghdr * msg, int level, int type= , int len, void *data) =20 check_object_size(data, cmlen - sizeof(*cm), true); =20 - if (can_do_masked_user_access()) - cm =3D masked_user_access_begin(cm); - else if (!user_write_access_begin(cm, cmlen)) - goto efault; - - unsafe_put_user(cmlen, &cm->cmsg_len, efault_end); - unsafe_put_user(level, &cm->cmsg_level, efault_end); - unsafe_put_user(type, &cm->cmsg_type, efault_end); - unsafe_copy_to_user(CMSG_USER_DATA(cm), data, - cmlen - sizeof(*cm), efault_end); - user_write_access_end(); + scoped_user_write_access_size(cm, cmlen, efault) { + unsafe_put_user(cmlen, &cm->cmsg_len, efault); + unsafe_put_user(level, &cm->cmsg_level, efault); + unsafe_put_user(type, &cm->cmsg_type, efault); + unsafe_copy_to_user(CMSG_USER_DATA(cm), data, + cmlen - sizeof(*cm), efault); + } } else { struct cmsghdr *cm =3D msg->msg_control; =20 @@ -301,8 +297,6 @@ int put_cmsg(struct msghdr * msg, int level, int type, = int len, void *data) msg->msg_controllen -=3D cmlen; return 0; =20 -efault_end: - user_write_access_end(); efault: return -EFAULT; } --=20 2.49.0 From nobody Tue Dec 2 02:52:29 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 995C62FC02F; Mon, 17 Nov 2025 16:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763398256; cv=none; b=fQ6ytzf9kCSbo7KQCdmgQ46i7jC4HwwPHG8FetkMlcdL9SfD9s0BovgFDLbbzubHX7ui64FhVcRb07rBDdIhs66bL59TkjnJRtVy63MTxnA0iavIarQYcZ+XZ41JAWLt0sefZrggnRo0O9F9mKPH7EcRYTBZXKYKMDE7KqcCzUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763398256; c=relaxed/simple; bh=qDckhyWd5Xp/iUbxoRJgosMNjecj8byVLupzPsFbxdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l/9oyjZvJMhJZ741l9iecsMdhMhgZcdmlEAxHoKri3QiUniULuaOcgrgRKgJgcFGj9gSKAE4JmAz7xtfrvntMQKIqP+jbnvbUVkSzTim2LOduJb2IXEfDvxjJOa0xMcecUTVC2mqqn1RZ5CDnrfIJKI5Ki90WUS2CVjpd/MJW1A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub4.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4d9D9B0fVlz9sTk; Mon, 17 Nov 2025 17:44:14 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eU0hj9tte4dv; Mon, 17 Nov 2025 17:44:14 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4d9D996cx9z9sTj; Mon, 17 Nov 2025 17:44:13 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CE2E78B763; Mon, 17 Nov 2025 17:44:13 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id tff4OGSdT2mn; Mon, 17 Nov 2025 17:44:13 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.235.99]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A48D28B768; Mon, 17 Nov 2025 17:44:12 +0100 (CET) From: Christophe Leroy To: Thomas Gleixner , Peter Zijlstra Cc: Christophe Leroy , Alexander Viro , Christian Brauner , Jan Kara , Ingo Molnar , Darren Hart , Davidlohr Bueso , "Andre Almeida" , Andrew Morton , Eric Dumazet , Kuniyuki Iwashima , Paolo Abeni , Willem de Bruijn , "David S. Miller" , Jakub Kicinski , Simon Horman , Daniel Borkmann , Dave Hansen , Madhavan Srinivasan , Michael Ellerman , Nichlas Piggin , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v5 4/4] lib/strn*,uaccess: Use masked_user_{read/write}_access_begin when required Date: Mon, 17 Nov 2025 17:43:44 +0100 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2306; i=christophe.leroy@csgroup.eu; h=from:subject:message-id; bh=qDckhyWd5Xp/iUbxoRJgosMNjecj8byVLupzPsFbxdU=; b=owGbwMvMwCV2d0KB2p7V54MZT6slMWRKB5zwcf5XZ8nQsPWQR3SBdCH7ipUnHdxv1zv7Ku9On 1xYOe1CRykLgxgXg6yYIsvx/9y7ZnR9Sc2fuksfZg4rE8gQBi5OAZjIyQJGhg+x8vzW+28u3+X+ ZFGOZmr8v6hj/g/nf9VfOM1v700nrukM/71WCtXdYlPy+rWCe77xJ9dct9gfnaqndGPERLYczlm gxQkA X-Developer-Key: i=christophe.leroy@csgroup.eu; a=openpgp; fpr=10FFE6F8B390DE17ACC2632368A92FEB01B8DD78 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Properly use masked_user_read_access_begin() and masked_user_write_access_begin() instead of masked_user_access_begin() in order to match user_read_access_end() and user_write_access_end(). This is important for architectures like powerpc that enable separately user reads and user writes. That means masked_user_read_access_begin() is used when user memory is exclusively read during the window and masked_user_write_access_begin() is used when user memory is exclusively writen during the window. masked_user_access_begin() remains and is used when both reads and writes are performed during the open window. Each of them is expected to be terminated by the matching user_read_access_end(), user_write_access_end() and user_access_end(). Signed-off-by: Christophe Leroy --- v5: - Removed net/core/scm.c which is converted to scope user access by previou= s patch - Renamed the patch as it now only handles lib/strncpy_from_user.c and lib/= strnlen_user.c v4: Rebased on top of core-scoped-uaccess tag v3: Rebased on top of v6.18-rc1 =3D=3D> change in net/core/scm.c v2: Added more explanations in the commit message following comments receiv= ed. --- lib/strncpy_from_user.c | 2 +- lib/strnlen_user.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c index 6dc234913dd5..5bb752ff7c61 100644 --- a/lib/strncpy_from_user.c +++ b/lib/strncpy_from_user.c @@ -126,7 +126,7 @@ long strncpy_from_user(char *dst, const char __user *sr= c, long count) if (can_do_masked_user_access()) { long retval; =20 - src =3D masked_user_access_begin(src); + src =3D masked_user_read_access_begin(src); retval =3D do_strncpy_from_user(dst, src, count, count); user_read_access_end(); return retval; diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c index 6e489f9e90f1..4a6574b67f82 100644 --- a/lib/strnlen_user.c +++ b/lib/strnlen_user.c @@ -99,7 +99,7 @@ long strnlen_user(const char __user *str, long count) if (can_do_masked_user_access()) { long retval; =20 - str =3D masked_user_access_begin(str); + str =3D masked_user_read_access_begin(str); retval =3D do_strnlen_user(str, count, count); user_read_access_end(); return retval; --=20 2.49.0