Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1148264rwd; Wed, 7 Jun 2023 11:42:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hrIRK/GKLO0b49ZKG5gUvqR5mUdhIXn7nTrdvwi0TQb3EU2elsX9b1QH5l8o0p62hPXzx X-Received: by 2002:a05:6a00:2d84:b0:65a:1efc:13ca with SMTP id fb4-20020a056a002d8400b0065a1efc13camr5644467pfb.15.1686163376110; Wed, 07 Jun 2023 11:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686163376; cv=none; d=google.com; s=arc-20160816; b=S1q7jMXaw6W2WJUNeo7QNbHa5r3yluwO7Axo1JAuyzbbQcY1Ypr+M+GJqCM58kAxyb S6q1qwsZJbM+wAHjmTLnsZLl9tSMhkf/fs3qlP0jOLtolUZNvFlWo5JWOJXbC4kzAdeJ LKJVe4ocE7NBHJOhTSMayb+Hb2k9pW6ipu6rthLKNFajdj8udy3rsfypzc8V+DWwcaSu mMeWtK14hUgwH1oKXOOEs31y4s45qukEFuKemwkz8TVPXwsbOmJ1knwXeObjHlO6fgTl vDAAeSW3c94bdEcVRTQtZWVSNBBO+Sgem95qabHkRd6hNaIUVCbVT5DXAnfh6OWODLgN J7TA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z18-20020aa79592000000b0064d2cca82b1si9266217pfj.48.2023.06.07.11.42.42; Wed, 07 Jun 2023 11:42:56 -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 S231761AbjFGSUq (ORCPT + 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 ); 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 ; 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 To: netdev@vger.kernel.org, Linus Torvalds Cc: David Howells , Chuck Lever , Boris Pismenny , John Fastabend , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 cc: Jakub Kicinski cc: Chuck Lever cc: Boris Pismenny cc: John Fastabend cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox 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