[net-next,v6,01/14] net: Block MSG_SENDPAGE_* from being passed to sendmsg() by userspace
Message ID | 20230607181920.2294972-2-dhowells@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp408863vqr; Wed, 7 Jun 2023 11:45:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4e4nove6Xq6o7qHOg/w4z0Wz8XloDiZXwGr4rEK8IrkilJScgl9tk8eDTN9z5ZlnhoD749 X-Received: by 2002:a05:6a00:189f:b0:64f:7a9c:cb15 with SMTP id x31-20020a056a00189f00b0064f7a9ccb15mr4940480pfh.11.1686163512652; Wed, 07 Jun 2023 11:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686163512; cv=none; d=google.com; s=arc-20160816; b=DvFyOCgPaV36x6FnoLVfibNnX69K11ri4EcfZB2/nAsO0jQriv7HsSAMyb9W7TKwLh mGyCevRDGLe6Ij0ZEo8fOr9I1IcyzO22IYt3XM+RrGsUWXsFDz/B0cd4E09el8QFyXEK TyPZOrmtU6RdhUxzv75gwWtlnMCeLf49F6lOTs27Y4vLxcg1Xx1UKArzdeFJSqC3OPCL gylT/lhwl8YX0zG222gFsj0Oopfz5g6wJQH5P9dB6CxzyGwYem2n62n9HpTxEPkXX9zE MKffzLolOcZY9GR9SmRa0GNPU3XblW7bZ/kCFjsVh3ggnLTqtv9/5fFKlMjQEF1WOWMt TPWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=704Gul1es5vKB8f3fNlqLP0xfed1dEhsuWb+SLm3klg=; b=n3h1gaI20yWMUiTSt5DHUyTEqhB+Llb+EhGeFC5AzvkPQgNVrA5ND7vGeq5Ed3rZzy +nFlptSLyZBQSjmisYgU/iM4VJaTFXu5dz5V0ERuj7+EVflRLnAbVDJzCM/SH28O5SPJ LULgbhTbXVseO/p1dfUplKHv41MfSQM4OtsS/AMkkjjcE+YIua/I4hve4e6i7/SIclQn Mp7WnhGtrH3GsQV3Sy0RehmUfLJULss/n8niQOVEb6EY1nZZse3/KitmqoIUaJOSR4MI PGETzV+jRFxmYsMR176A4vgfwaZlNwTG7T5yamRjDIrZS+Y3ZRZ0FZrPrXsGAXLmArFD JC2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X+75NLCH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p13-20020a63ab0d000000b0053ef1799a71si9029332pgf.399.2023.06.07.11.45.00; Wed, 07 Jun 2023 11:45:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X+75NLCH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231844AbjFGSUq (ORCPT <rfc822;literming00@gmail.com> + 99 others); Wed, 7 Jun 2023 14:20:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233131AbjFGSUT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 7 Jun 2023 14:20:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F43495 for <linux-kernel@vger.kernel.org>; Wed, 7 Jun 2023 11:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686161973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=704Gul1es5vKB8f3fNlqLP0xfed1dEhsuWb+SLm3klg=; b=X+75NLCHdNw9IUdjV0vY4keSL11jwbhdJAxDrikGBHUkfYJGVjJRj8ZaUW3Uskf5RMZg9E 2IOkwpXxe6PsJdgmdyvDAw7fCJ/JZ2sMrkCmVdLqwq0AypDbRBZJ2ozmCsvKLL8jFxS0/z 0ABj1JALZcyy4sshI3xFqbR5r0xRwHA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-639-mJrSACM1MtWkA-dGsaZ40A-1; Wed, 07 Jun 2023 14:19:30 -0400 X-MC-Unique: mJrSACM1MtWkA-dGsaZ40A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B083C3C0F220; Wed, 7 Jun 2023 18:19:28 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4158140D1B66; Wed, 7 Jun 2023 18:19:26 +0000 (UTC) From: David Howells <dhowells@redhat.com> To: netdev@vger.kernel.org, Linus Torvalds <torvalds@linux-foundation.org> Cc: David Howells <dhowells@redhat.com>, Chuck Lever <chuck.lever@oracle.com>, Boris Pismenny <borisp@nvidia.com>, John Fastabend <john.fastabend@gmail.com>, Jakub Kicinski <kuba@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com>, Willem de Bruijn <willemdebruijn.kernel@gmail.com>, David Ahern <dsahern@kernel.org>, Matthew Wilcox <willy@infradead.org>, Jens Axboe <axboe@kernel.dk>, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v6 01/14] net: Block MSG_SENDPAGE_* from being passed to sendmsg() by userspace Date: Wed, 7 Jun 2023 19:19:07 +0100 Message-ID: <20230607181920.2294972-2-dhowells@redhat.com> In-Reply-To: <20230607181920.2294972-1-dhowells@redhat.com> References: <20230607181920.2294972-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768070591431656814?= X-GMAIL-MSGID: =?utf-8?q?1768070591431656814?= |
Series |
splice, net: Rewrite splice-to-socket, fix SPLICE_F_MORE and handle MSG_SPLICE_PAGES in AF_TLS
|
|
Commit Message
David Howells
June 7, 2023, 6:19 p.m. UTC
It is necessary to allow MSG_SENDPAGE_* to be passed into ->sendmsg() to
allow sendmsg(MSG_SPLICE_PAGES) to replace ->sendpage(). Unblocking them
in the network protocol, however, allows these flags to be passed in by
userspace too[1].
Fix this by marking MSG_SENDPAGE_NOPOLICY, MSG_SENDPAGE_NOTLAST and
MSG_SENDPAGE_DECRYPTED as internal flags, which causes sendmsg() to object
if they are passed to sendmsg() by userspace. Network protocol ->sendmsg()
implementations can then allow them through.
Note that it should be possible to remove MSG_SENDPAGE_NOTLAST once
sendpage is removed as a whole slew of pages will be passed in in one go by
splice through sendmsg, with MSG_MORE being set if it has more data waiting
in the pipe.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Boris Pismenny <borisp@nvidia.com>
cc: John Fastabend <john.fastabend@gmail.com>
cc: Eric Dumazet <edumazet@google.com>
cc: "David S. Miller" <davem@davemloft.net>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Jens Axboe <axboe@kernel.dk>
cc: Matthew Wilcox <willy@infradead.org>
cc: netdev@vger.kernel.org
Link: https://lore.kernel.org/r/20230526181338.03a99016@kernel.org/ [1]
---
include/linux/socket.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/linux/socket.h b/include/linux/socket.h index bd1cc3238851..3fd3436bc09f 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -339,7 +339,9 @@ struct ucred { #endif /* Flags to be cleared on entry by sendmsg and sendmmsg syscalls */ -#define MSG_INTERNAL_SENDMSG_FLAGS (MSG_SPLICE_PAGES) +#define MSG_INTERNAL_SENDMSG_FLAGS \ + (MSG_SPLICE_PAGES | MSG_SENDPAGE_NOPOLICY | MSG_SENDPAGE_NOTLAST | \ + MSG_SENDPAGE_DECRYPTED) /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */ #define SOL_IP 0