Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp628800img; Mon, 18 Mar 2019 10:36:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNfQZZy3adO1tRu5bVZRoh1ZPE/K8mHznLZ8YFQpJERZzQITj3sNTmKQb/UwU4oZ/bkZ5u X-Received: by 2002:a62:1881:: with SMTP id 123mr3290706pfy.25.1552930588076; Mon, 18 Mar 2019 10:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552930588; cv=none; d=google.com; s=arc-20160816; b=JzGUjoQYEPBzSYrWWemRg40zg+Ls25BmaakGyKW4x1/a3NUdX3J39X8F6tI8CURpKS kCYRSGx/dA+iH7oidnUK/bk/Tnv4z+srI6mg9/Z4v1tETENS1Z3Xv5H8xXTqXHEFYLcU oAI0sgu3RCCmh5d8Luf52EOHb9aK51fjeU/5uhFJVdaauZimrilWz2lc2AY1aKttsnvY nQqhocebsHAsaDWh2GycynhLYl4GQeWtaAjOCsgrqvm6smgLXTAkH7bcH8apqAI9atnQ mvJjpyhKwzqY1RlURoZP6mfoOwCd1rTlybeGfxwlSNCrjdpTmRLl6oz3nqJvS2nsjS4h WIQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PrCO2lU0ZipPiiy31J0umfmtEn4o5iLh0G0tXGxKdqM=; b=Dn/j5oPXN6Evzx+9O3Yjt8CrXU2gby+Rgu8Gt7JviMv9Tt0E7uUBLASW2GW5I3D/kT 52NkulyEBNAt5NUiFTYeeNbjXX9xJlboZ+3E7NYVyQSw9NZktkdf57ugT4K+9c7fsRGF TnexPAYORzh+EnFKJRWj5QSRU8U5ZPE1psIXYcqLNSui+AbsILRwWsCEM5fMmUOBNemu tPsshqnlok1QK4WppbrvIqdGQFJuY1USd1jyIsUojQBWBw93n+V7+PzWF2dZHL5bBWwe tThZ+tqgVz69q8d6mp+lmfSihP7n5qF7y/tRo32QQNXO4oaSHwdoyoaydde4dgdTsb6T VFoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uyrIqaY7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11si9585535plo.400.2019.03.18.10.36.12; Mon, 18 Mar 2019 10:36:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uyrIqaY7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727267AbfCRRf3 (ORCPT + 99 others); Mon, 18 Mar 2019 13:35:29 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:52484 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726720AbfCRRf2 (ORCPT ); Mon, 18 Mar 2019 13:35:28 -0400 Received: by mail-it1-f193.google.com with SMTP id g17so21752081ita.2 for ; Mon, 18 Mar 2019 10:35:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PrCO2lU0ZipPiiy31J0umfmtEn4o5iLh0G0tXGxKdqM=; b=uyrIqaY7oC9B9nG/UxXrp2razNOLtRgLgzTki3DkPSo3hKZBihhOVs5XMPl0tSTbG9 8BkxMAekwOpEr5c18J94vX/PHkd/cR8S37JaGiHv2rHoQtCm8VN0JQT4bVDxL4DnFuaf TBpB7mtD1xZMSM6CEOwzN6ylMmjBtpj/81knOnGPRXtUhR49sy3r7rujNqeJpemmcNe/ yahcAmwycILMB5vkZoN8PLSOFNCEEoAnrHt4dlbEmOy7anc6ZJcANenVW5WZHg63bVhQ EDhXKW0Z+zXP/J6GAQ7GCYiiP+UrBe+V732dR9WdPtz9JuQLQBUDqkDSRPo5Tqt0+iTo c1OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PrCO2lU0ZipPiiy31J0umfmtEn4o5iLh0G0tXGxKdqM=; b=ZCC0lOLfzDe6n8LjK5jlxQv0VeECacwF+cf4K8hhnHgWpZiIvBdUCk3nj7iVJlmakD 65Ugjd0nqd+Ns/V7sO/04NRhBhoAwZCcz+DfjT3fxHFokBi3IDSTJ5Uuyu/JAxsiXN9s mvUTFhpd1JmZ9CNht+WzgPsRX2k+t1KLhUrCfymJxT8ROaoD+ZNJx9JCBXQE+9ao9V/M F6B2tFxEP6jRNh07FdkN4f4Q/dDH6ljCqpiw22Utz3/zlksTXGfNciAQImo1Nkrf2N8k 36x7FHNRRiHFPQTYlSDWn/alrdpFLk35PDijtVv3NuRF9oN475zV/2QAPOmkmjJcbjgZ UyYg== X-Gm-Message-State: APjAAAWtgrPpAKOjev3tdgLYrMcS7era2XJqWrX5gbJcpMabySoN5GBx pJUwDCEphcbiMmtkXEa/v1iA3RcphMD8noNnD9W+HA== X-Received: by 2002:a05:660c:842:: with SMTP id f2mr25940itl.142.1552930526937; Mon, 18 Mar 2019 10:35:26 -0700 (PDT) MIME-Version: 1.0 References: <80e79c47dc7c5ee3572034a1d69bb724fbed2ecb.1552929301.git.andreyknvl@google.com> In-Reply-To: <80e79c47dc7c5ee3572034a1d69bb724fbed2ecb.1552929301.git.andreyknvl@google.com> From: Eric Dumazet Date: Mon, 18 Mar 2019 10:35:14 -0700 Message-ID: Subject: Re: [PATCH v12 08/13] net, arm64: untag user pointers in tcp_zerocopy_receive To: Andrey Konovalov Cc: Catalin Marinas , Will Deacon , Mark Rutland , Robin Murphy , Kees Cook , Kate Stewart , Greg Kroah-Hartman , Andrew Morton , Ingo Molnar , "Kirill A . Shutemov" , Shuah Khan , Vincenzo Frascino , "David S. Miller" , Alexei Starovoitov , Daniel Borkmann , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Arnaldo Carvalho de Melo , Linux ARM , "open list:DOCUMENTATION" , linux-mm , linux-arch , netdev , bpf , "open list:KERNEL SELFTEST FRAMEWORK" , LKML , Dmitry Vyukov , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Chintan Pandya , Luc Van Oostenryck , Dave Martin , Kevin Brodsky , Szabolcs Nagy Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 18, 2019 at 10:18 AM Andrey Konovalov wrote: > > This patch is a part of a series that extends arm64 kernel ABI to allow to > pass tagged user pointers (with the top byte set to something else other > than 0x00) as syscall arguments. > > tcp_zerocopy_receive() uses provided user pointers for vma lookups, which > can only by done with untagged pointers. > > Untag user pointers in this function. > > Signed-off-by: Andrey Konovalov > --- > net/ipv4/tcp.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c > index 6baa6dc1b13b..e76beb5ff1ff 100644 > --- a/net/ipv4/tcp.c > +++ b/net/ipv4/tcp.c > @@ -1749,7 +1749,7 @@ EXPORT_SYMBOL(tcp_mmap); > static int tcp_zerocopy_receive(struct sock *sk, > struct tcp_zerocopy_receive *zc) > { > - unsigned long address = (unsigned long)zc->address; > + unsigned long address; > const skb_frag_t *frags = NULL; > u32 length = 0, seq, offset; > struct vm_area_struct *vma; > @@ -1758,7 +1758,12 @@ static int tcp_zerocopy_receive(struct sock *sk, > int inq; > int ret; > > - if (address & (PAGE_SIZE - 1) || address != zc->address) > + address = (unsigned long)untagged_addr(zc->address); > + > + /* The second test in this if detects if the u64->unsigned long > + * conversion had any truncated bits. > + */ > + if (address & (PAGE_SIZE - 1) || address != untagged_addr(zc->address)) > return -EINVAL; > > if (sk->sk_state == TCP_LISTEN) This is quite ugly, the comment does not really help nor belong to this patch. What about using untagged_addr() only once ? diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 6baa6dc1b13b0b94b1da238668b93e167cf444fe..855a1f68c1ea9b0d07a92bd7f5e7c24840a99d3d 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1761,6 +1761,8 @@ static int tcp_zerocopy_receive(struct sock *sk, if (address & (PAGE_SIZE - 1) || address != zc->address) return -EINVAL; + address = untagged_addr(address); + if (sk->sk_state == TCP_LISTEN) return -ENOTCONN;