Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2358703rwd; Fri, 2 Jun 2023 08:21:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64FzCwhm/kCcDbo1t+NPndGtilVLaNsna6nCt8yESyadvFZs+34ttYZHavZ/7JbCzrBhPf X-Received: by 2002:a05:6358:24a3:b0:11c:7287:8add with SMTP id m35-20020a05635824a300b0011c72878addmr5765010rwc.20.1685719270630; Fri, 02 Jun 2023 08:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685719270; cv=none; d=google.com; s=arc-20160816; b=R6qngamKKd31bQVOv3em9KFCS+JTTenvYwNAVmLo0yyGLk2B87v1ChdE0diRgSmHOr o0qzxoGu2EdiajFD8zJe783t3VdKmUFvP2Skb2K4r83RblhiX0tqpLJu2wUaH4MOJzUX 0PM7VWa4I3fWrhh9kHKleauvbJ94+J/8q2zn25vil4T2HV3Uw1zRinqJcdDtxZ2W9Pp7 x+Y2RnINCTTVOxo7yOtXGryC9d3IH4JmkCrImTN4uts1fx0k+3BoKlxwOEgDq+78k+4w 9uRakeby57Aqf9t1kSoVRnMsMH+YDH+lIg0+nt47p6swbnT2JI0/wrZhJ82lD2WyxlQ4 P3RQ== 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=w5tqCHvpfZzd1Wdlar8+zS7f4tVN4V7jpxdM5Ts1tbjid2WBwb2GSuZPEX+d0FL1zu KJPWGL2Vc6FIbd13UFoG7HM6kcqcGOXHLjDlLteG+YIehblc+UqVI7ylyQI6OUfYEXBI WWMdyKGU6lacA5e4WDZDi/nO9i8FaXlObQgWlo9l8/W9R1VSew0Ls7D+V0VksWMmy3pH HwrFFLJbEZTOWjGo6oD/Fmw1stBzJo4gzlR3oId8v6EDTym4rvPjLDxY0lTPWzqi50CU 8Op1iwk1OQpH5rNO02iIb62l/p9HyX6u6SxWaubzGIHRlIDej67oYWr6KgP3nuCfZUfr +lDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ezR4Jv+I; 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 s12-20020a17090aa10c00b002562a054821si1173994pjp.138.2023.06.02.08.20.56; Fri, 02 Jun 2023 08:21:10 -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=ezR4Jv+I; 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 S235118AbjFBPI4 (ORCPT + 99 others); Fri, 2 Jun 2023 11:08:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236399AbjFBPIw (ORCPT ); Fri, 2 Jun 2023 11:08:52 -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 200B3E40 for ; Fri, 2 Jun 2023 08:08:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685718487; 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=ezR4Jv+I6jK3jXYv4Os435NCkQLkWH+QFa6voNVOGu37lgyXsC1FG8PjvIVcfA/rLhPr9z HcPho5yui9kWCYBvizxf1c68PmHhRwMFwTju1E8BzAV5cwgJNIewW+iy1SywY1UV9bdN3l s7b0svNiz1Ud6NXxK73iggfLCho87tQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-157-98r-sCduMDuRZbV631FDtg-1; Fri, 02 Jun 2023 11:08:02 -0400 X-MC-Unique: 98r-sCduMDuRZbV631FDtg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 86197185A792; Fri, 2 Jun 2023 15:08:01 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F0642026D49; Fri, 2 Jun 2023 15:07:59 +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 v3 01/11] net: Block MSG_SENDPAGE_* from being passed to sendmsg() by userspace Date: Fri, 2 Jun 2023 16:07:42 +0100 Message-ID: <20230602150752.1306532-2-dhowells@redhat.com> In-Reply-To: <20230602150752.1306532-1-dhowells@redhat.com> References: <20230602150752.1306532-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-2.3 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