From patchwork Thu Apr 6 09:42:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13203061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AD0BC76196 for ; Thu, 6 Apr 2023 09:43:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82AFC6B0095; Thu, 6 Apr 2023 05:43:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 800BD6B0096; Thu, 6 Apr 2023 05:43:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6525D6B0098; Thu, 6 Apr 2023 05:43:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 580316B0095 for ; Thu, 6 Apr 2023 05:43:41 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2EF6F1411B8 for ; Thu, 6 Apr 2023 09:43:41 +0000 (UTC) X-FDA: 80650479042.21.CA1C111 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 750D740015 for ; Thu, 6 Apr 2023 09:43:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="APTj/8YK"; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680774219; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Lhpi7afnUSYBVmFcNV33/AfpfwJkESufDM5kupMXc5M=; b=l18bEJNK2QQNBwykmk/0ZwXSV9yAcVs6WPtZyPfTl9dUQVL9+UJbSt09uCUTPLUQIjOL8o V1QhuBUFR0R0XWPPzQ5X1RB6NPsa8w7rebdAYJbO5Dcm7JRSCFRKi3fe1SE1hVfXf6rWOp fm7lvZr0X+Iw3trQNnItxPmZtuSybLs= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="APTj/8YK"; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680774219; a=rsa-sha256; cv=none; b=wZfLQTkeZEWQCm6vOVck8fMHlGMBirPLnopp9TOojXG24zH7fsi8+5YV88lMffNMRlUEoJ eYj2Z+9ce3ogIvvCdsHcCSSXcRczK0x+du767LPkhYAuqKmAsHZ23XQIb3zhY+u25NVrZV Xyt1KPaRirlew/KvtaHkgBzfp7+fWls= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680774218; 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=Lhpi7afnUSYBVmFcNV33/AfpfwJkESufDM5kupMXc5M=; b=APTj/8YKiarlb4Q8hIrsVFbE+YiCU22qbJQASZqWpFRqCsnwavRncVQcO3MVF05fB8Tg/y rkhxT919FItO9I6JE07Q7u21ioishcdwZ/WDWqoTuLQoT5svzverlX0djz54MXDnloezSN oksxP4aJrZJp5sfl/3zF8As6xa7MD9k= 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-387-ZCLBzN6RN_yR-HE_tGR4oA-1; Thu, 06 Apr 2023 05:43:34 -0400 X-MC-Unique: ZCLBzN6RN_yR-HE_tGR4oA-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 D9DE93C0ED40; Thu, 6 Apr 2023 09:43:33 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6DC0202701F; Thu, 6 Apr 2023 09:43:31 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Matthew Wilcox , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Chuck Lever III , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, David Ahern Subject: [PATCH net-next v5 14/19] ip, udp: Make sendmsg(MSG_SPLICE_PAGES) copy unspliceable data Date: Thu, 6 Apr 2023 10:42:40 +0100 Message-Id: <20230406094245.3633290-15-dhowells@redhat.com> In-Reply-To: <20230406094245.3633290-1-dhowells@redhat.com> References: <20230406094245.3633290-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 750D740015 X-Stat-Signature: 5ys3sfiew7xyx957x4mju8e3acc96bxd X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1680774219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P8+aEFhF0yLKWX85NAq8/hPkRR9yFAAVkm6zc04pY9m/FtTcb8opcLBASfnikj1Zm992T7609wDZQFrNR7mLUNWCVNHOQZXeQSoDBebJPsqMWohU/AQ57Z8YxW/GdTCVG9YP+fKkoszXUz2F2yAhldjD4xF23ito5TsN0FXDErh8eloXym0oajonTYHpSHLJyq4xZdhc/i+/yLr3xW8LeTvb9+fn/R0SPTGk0TcEHnINWx6VeC3OL+tF5ZCJRT4sBk7rLFJF8jYP5cIi7k1ZuriTn9EpyoSXqt5u+OigZX5Njoa5nrLI83mJvB/milrSVTH3y1H65fx7Rkh/TYOoZt6pqc3S7qr/0YJDAYz1VpS7znX5jETLUTzLKlpDFjD+i6G8HgFd8wF5VSbtPG3YG37MstWQ9inJQWoOfKJvFHrKaIyVhzw84hzAml4gRXkDp2WQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If sendmsg() with MSG_SPLICE_PAGES encounters a page that shouldn't be spliced - a slab page, for instance, or one with a zero count - make __ip_append_data() copy it. Signed-off-by: David Howells cc: Willem de Bruijn cc: David Ahern cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- net/ipv4/ip_output.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index c6c318eb3d37..48db7bf475df 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -967,13 +967,32 @@ static int __ip_splice_pages(struct sock *sk, struct sk_buff *skb, struct page *page = NULL, **pages = &page; ssize_t copy = *pcopy; size_t off; + bool put = false; int err; copy = iov_iter_extract_pages(&msg->msg_iter, &pages, copy, 1, 0, &off); if (copy <= 0) return copy ?: -EIO; + if (!sendpage_ok(page)) { + const void *p = kmap_local_page(page); + void *q; + + q = page_frag_memdup(NULL, p + off, copy, + sk->sk_allocation, ULONG_MAX); + kunmap_local(p); + if (!q) { + iov_iter_revert(&msg->msg_iter, copy); + return -ENOMEM; + } + page = virt_to_page(q); + off = offset_in_page(q); + put = true; + } + err = skb_append_pagefrags(skb, page, off, copy); + if (put) + put_page(page); if (err < 0) { iov_iter_revert(&msg->msg_iter, copy); return err;