Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5576316rwd; Mon, 5 Jun 2023 05:52:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7oogrnL8IDCLxAoFoOa04uGhXGs6JLNfVUa+skaxnxFxuoVMMne7SSXEFTs7sshVJjGkje X-Received: by 2002:a05:6358:c097:b0:129:a24c:f696 with SMTP id fa23-20020a056358c09700b00129a24cf696mr1907951rwb.29.1685969541383; Mon, 05 Jun 2023 05:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685969541; cv=none; d=google.com; s=arc-20160816; b=QBvNlRgeoIa2jEuv0VKsOmGpFiOVQo5o8Yes2qJDHOB6DHxA5tPeq3DhNP2OPrnXyU U20kfpN/DqaMO1zmAraaSa0pcSR6xrgrDDYWVhrngUx/52xM4l+xuxwpDJueqhM9xODp K57nJHAvVGqb1OEWiawVQyZtemxJXqYI6ffA7KBj7AeuOLtV1mtOx+3KXDlM/rLxPkgS BGpAthXKqSJx+SsWDif/P7K8gOWF5J5IgVJnV2y5pgr18p3LO8hakSky9HBfO0htuT49 WP0AhefCnRO82tNvBzGCKnV+yQ7q3LlbMGDjipg6mR/09P/5qFH2ts/uhPmibqKL6MXC h08w== 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=POAh7sSBOsQofDmEI6/Qdvv4oq79K5FC08DkMn5ErFbWuESXwg7DRkpi1zWvAWwBxL w9Rtp1vabcq6uKz+xl8JvJYpElHSzXm3G48w+m2Nx2CC4nHQsVl4AjJB8nI2Ep138ObC Yzb3+GpcHyR9OuxbKYoVg+o6ndzxNjopN4zA59gb8kGkHJyQ0zSXNrnZptseRz8CgEoq wyKmE3Ku81cwhXG16OyOc4DjQPJ8Xf7i1DFH8mWQOFDAJabTS1p8OsgKm5oXiRIyBp+o /dgh4L9IqBtlPlNZwXmynNOXjjJE2/2q14pFjGRcXweEwguUOt9M3KXYdZiWkWlzzMqD FVHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CHr9+w62; 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 lc3-20020a17090b158300b0022c24bf1810si5448881pjb.29.2023.06.05.05.52.07; Mon, 05 Jun 2023 05:52:21 -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=CHr9+w62; 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 S233357AbjFEMrE (ORCPT + 99 others); Mon, 5 Jun 2023 08:47:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232896AbjFEMrB (ORCPT ); Mon, 5 Jun 2023 08:47:01 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 491CB98 for ; Mon, 5 Jun 2023 05:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685969172; 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=CHr9+w62TEpawCNwoKX4Pc8i7mGlzNcBlA0w9umac9MspqPJaSQe9c2uXe0H2GUNWh6iI1 +nSev6Y7jtoQRFj9r3XG435qkwQDnZSx6WVdXKH17dAyUCUooRlDVMQoSmWkWRBVmkJbvX ekXHZt4XML5/N+RqZt+XrLFJD95czvo= 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-638-MPVBXKHIMYqM4_90ThZprA-1; Mon, 05 Jun 2023 08:46:09 -0400 X-MC-Unique: MPVBXKHIMYqM4_90ThZprA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67A5C1C0878A; Mon, 5 Jun 2023 12:46:08 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 682677AE4; Mon, 5 Jun 2023 12:46:06 +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 v4 01/11] net: Block MSG_SENDPAGE_* from being passed to sendmsg() by userspace Date: Mon, 5 Jun 2023 13:45:50 +0100 Message-ID: <20230605124600.1722160-2-dhowells@redhat.com> In-Reply-To: <20230605124600.1722160-1-dhowells@redhat.com> References: <20230605124600.1722160-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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=ham 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