Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1128171pxk; Fri, 2 Oct 2020 01:31:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGvl4RFA2pSPnErxnEmeiGsd4aP8QxMTD9JX5bhfM7bemb1BVl8mLmlXoZHgHbXv7zlKda X-Received: by 2002:aa7:d843:: with SMTP id f3mr1111030eds.115.1601627473829; Fri, 02 Oct 2020 01:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601627473; cv=none; d=google.com; s=arc-20160816; b=WgywEJz4A64rlQce/1oJCW3Cu5XIxn65Fa93yp9xQFHcxs+d1Zk3G5bhD8/8ulykKT 3Pc6mCbVBxKOGQ6oGsbazGK0uAp1ymUEh8ThqcwTZRsZy/ZwA54n7jKiCICVaNED0j+u tsEfTLmKSGbfJ6c8ULf9YIzBtZIFrUNHUwyIAGNQNprCSiNWDszMSqCw9bhT9fhoyqk2 IC7Am8BjWrU4euWvvxG+1UugKZqS8unMrqJ3cgplxIzivvEPSEHUqNIdCsaRpPIjXWAN Kw0nkZi+YfvBBEI2nwzRij6OZNtilF0qwoRVkK7UFTAo986vOT7tz6LcHifufUjV632H D8hw== 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 :message-id:date:subject:cc:to:from; bh=kmckn98wjM/k1tDU2SqWUpNlYpqpR+WGdQRfGRspJIo=; b=s0RvdmrWbKTQ/B5WHJjK1Gun7Q8I79cUy7kG+WCtzVtbbZwcGZ3YI5mhE4BLLol9ch aMfYSWN3qCNLYUPXNs0SrccYRPd5hXe7syB4gfCDPrWhRkBRPL78aaZtDxxkYtKqS4G4 FkU3ZlgSO8j8Kg+cZr2pBv81OomrbtMyFeDhv2gnJ2qFfKojKHeHSTQy+oXY0bdjLVZY raVzWrleuQ8BqJ2FGSLshYskpJ3AEKIZCnrJSTmfk7uT5xTM81o8iQHpnMgkFHCR62MZ qj18EeDNFmvrSpinC3E2fQB3Didc0yHMhFO3hYPYycz9KO49rQ2asmNoZqseGmqbVrVR y1Xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x99si496202ede.160.2020.10.02.01.30.50; Fri, 02 Oct 2020 01:31:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387620AbgJBI1y (ORCPT + 99 others); Fri, 2 Oct 2020 04:27:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:49210 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbgJBI1y (ORCPT ); Fri, 2 Oct 2020 04:27:54 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 37D19AC82; Fri, 2 Oct 2020 08:27:52 +0000 (UTC) From: Coly Li To: davem@davemloft.net, linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, netdev@vger.kernel.org, open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org, ceph-devel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Coly Li , Chaitanya Kulkarni , Chris Leech , Christoph Hellwig , Cong Wang , Eric Dumazet , Hannes Reinecke , Ilya Dryomov , Jan Kara , Jeff Layton , Jens Axboe , Lee Duncan , Mike Christie , Mikhail Skorzhinskii , Philipp Reisner , Sagi Grimberg , Vasily Averin , Vlastimil Babka Subject: [PATCH v10 0/7] Introduce sendpage_ok() to detect misused sendpage in network related drivers Date: Fri, 2 Oct 2020 16:27:27 +0800 Message-Id: <20201002082734.13925-1-colyli@suse.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As Sagi Grimberg suggested, the original fix is refind to a more common inline routine: static inline bool sendpage_ok(struct page *page) { return (!PageSlab(page) && page_count(page) >= 1); } If sendpage_ok() returns true, the checking page can be handled by the concrete zero-copy sendpage method in network layer. The v10 series has 7 patches, fixes a WARN_ONCE() usage from v9 series, - The 1st patch in this series introduces sendpage_ok() in header file include/linux/net.h. - The 2nd patch adds WARN_ONCE() for improper zero-copy send in kernel_sendpage(). - The 3rd patch fixes the page checking issue in nvme-over-tcp driver. - The 4th patch adds page_count check by using sendpage_ok() in do_tcp_sendpages() as Eric Dumazet suggested. - The 5th and 6th patches just replace existing open coded checks with the inline sendpage_ok() routine. Coly Li Cc: Chaitanya Kulkarni Cc: Chris Leech Cc: Christoph Hellwig Cc: Cong Wang Cc: David S. Miller Cc: Eric Dumazet Cc: Hannes Reinecke Cc: Ilya Dryomov Cc: Jan Kara Cc: Jeff Layton Cc: Jens Axboe Cc: Lee Duncan Cc: Mike Christie Cc: Mikhail Skorzhinskii Cc: Philipp Reisner Cc: Sagi Grimberg Cc: Vasily Averin Cc: Vlastimil Babka --- Changelog: v10, fix WARN_ONCE() usage, and add Reivewed-by tag from Lee Duncan. v9, fix a typo pointed out by Greg KH. add Acked-by tags from Martin K. Petersen and Ilya Dryomov. v8: add WARN_ONCE() in kernel_sendpage() as Christoph suggested. v7: remove outer brackets from the return line of sendpage_ok() as Eric Dumazet suggested. v6: fix page check in do_tcp_sendpages(), as Eric Dumazet suggested. replace other open coded checks with sendpage_ok() in libceph, iscsi drivers. v5, include linux/mm.h in include/linux/net.h v4, change sendpage_ok() as an inline helper, and post it as separate patch, as Christoph Hellwig suggested. v3, introduce a more common sendpage_ok() as Sagi Grimberg suggested. v2, fix typo in patch subject v1, the initial version. Coly Li (7): net: introduce helper sendpage_ok() in include/linux/net.h net: add WARN_ONCE in kernel_sendpage() for improper zero-copy send nvme-tcp: check page by sendpage_ok() before calling kernel_sendpage() tcp: use sendpage_ok() to detect misused .sendpage drbd: code cleanup by using sendpage_ok() to check page for kernel_sendpage() scsi: libiscsi: use sendpage_ok() in iscsi_tcp_segment_map() libceph: use sendpage_ok() in ceph_tcp_sendpage() drivers/block/drbd/drbd_main.c | 2 +- drivers/nvme/host/tcp.c | 7 +++---- drivers/scsi/libiscsi_tcp.c | 2 +- include/linux/net.h | 16 ++++++++++++++++ net/ceph/messenger.c | 2 +- net/ipv4/tcp.c | 3 ++- net/socket.c | 6 ++++-- 7 files changed, 28 insertions(+), 10 deletions(-) -- 2.26.2