lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20220701105152.6920-1-fmdefrancesco@gmail.com>
Date:   Fri,  1 Jul 2022 12:51:52 +0200
From:   "Fabio M. De Francesco" <fmdefrancesco@...il.com>
To:     "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>,
        David Ahern <dsahern@...nel.org>,
        Pavel Begunkov <asml.silence@...il.com>,
        Wei Wang <weiwan@...gle.com>, Yangbo Lu <yangbo.lu@....com>,
        Richard Palethorpe <rpalethorpe@...e.com>,
        Thomas Gleixner <tglx@...utronix.de>, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org, bpf@...r.kernel.org
Cc:     "Fabio M. De Francesco" <fmdefrancesco@...il.com>,
        Ira Weiny <ira.weiny@...el.com>
Subject: [RFC PATCH] net: core: Replace kmap() with kmap_local_page()

The use of kmap() is being deprecated in favor of kmap_local_page().

With kmap_local_page(), the mappings are per thread, CPU local and not
globally visible. Taking page faults is allowed. Furthermore, the mappings
can be acquired from any context (including interrupts).

Therefore, use kmap_local_page() in sock.c and datagram.c because these
mappings are per thread, CPU local, and not globally visible.

Actually this is an RFC because I'm not 100% sure that the mappings in
sock.c are not handed over to other contexts. Unfortunately I know very
little about this code. The fact that "page" is kmapped and then kunmapped
before exiting sock_send_page*() is not a guarantee of thread locality.
That "kernel_sendmsg*()" is a bit "suspicious".

Can anyone please confirm whether or not "kaddr" is handed over to other
contexts while the call sites might sleep between kmap() / kunmap()?

Suggested-by: Ira Weiny <ira.weiny@...el.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@...il.com>
---
 net/core/datagram.c | 4 ++--
 net/core/sock.c     | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/core/datagram.c b/net/core/datagram.c
index 50f4faeea76c..3a8fa210e1a1 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -438,14 +438,14 @@ static int __skb_datagram_iter(const struct sk_buff *skb, int offset,
 		end = start + skb_frag_size(frag);
 		if ((copy = end - offset) > 0) {
 			struct page *page = skb_frag_page(frag);
-			u8 *vaddr = kmap(page);
+			u8 *vaddr = kmap_local_page(page);
 
 			if (copy > len)
 				copy = len;
 			n = INDIRECT_CALL_1(cb, simple_copy_to_iter,
 					vaddr + skb_frag_off(frag) + offset - start,
 					copy, data, to);
-			kunmap(page);
+			kunmap_local(vaddr);
 			offset += n;
 			if (n != copy)
 				goto short_copy;
diff --git a/net/core/sock.c b/net/core/sock.c
index 2ff40dd0a7a6..12dd6ced62cf 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3155,11 +3155,11 @@ ssize_t sock_no_sendpage(struct socket *sock, struct page *page, int offset, siz
 	ssize_t res;
 	struct msghdr msg = {.msg_flags = flags};
 	struct kvec iov;
-	char *kaddr = kmap(page);
+	char *kaddr = kmap_local_page(page);
 	iov.iov_base = kaddr + offset;
 	iov.iov_len = size;
 	res = kernel_sendmsg(sock, &msg, &iov, 1, size);
-	kunmap(page);
+	kunmap_local(kaddr);
 	return res;
 }
 EXPORT_SYMBOL(sock_no_sendpage);
@@ -3170,12 +3170,12 @@ ssize_t sock_no_sendpage_locked(struct sock *sk, struct page *page,
 	ssize_t res;
 	struct msghdr msg = {.msg_flags = flags};
 	struct kvec iov;
-	char *kaddr = kmap(page);
+	char *kaddr = kmap_local_page(page);
 
 	iov.iov_base = kaddr + offset;
 	iov.iov_len = size;
 	res = kernel_sendmsg_locked(sk, &msg, &iov, 1, size);
-	kunmap(page);
+	kunmap_local(kaddr);
 	return res;
 }
 EXPORT_SYMBOL(sock_no_sendpage_locked);
-- 
2.36.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ