Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3062854pxa; Tue, 18 Aug 2020 05:49:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8lZcvdv51uOwtT62z2XX21SPu+eWglvjFuigy9dEv+ALQq9NYk6eBqwO5BZl6w9U41lHg X-Received: by 2002:aa7:c259:: with SMTP id y25mr19207571edo.130.1597754954701; Tue, 18 Aug 2020 05:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597754954; cv=none; d=google.com; s=arc-20160816; b=JD/vpthoRMGBJidDPZ9xeQPNPvKFyoU+9m4JQLV3NHJR9NoKhNrZtKsHRXrOrGoMEr kqZ0AzJY2Xy6zVOuSVbqoUC/8tXqTijBmTVDA3vXzRS2lqNxj1tZXd+FU55lYkBGZT9s eCY5bX0WMWr5yVwha7X8zmI6MN87/sN6RnX0IYhuX/l+jvDnlWlNAwiRaORMPYBIOGkB hRmwMbEaCHuWFgYjgaTOve7Bs81QPy8dNQhTAsQBOcoOYWnL3BEErEyTJLhMJ9yzc2Cc yDB2TRfx+dfTHrrWRVEvUIGLmLjp7tfpKqMr4bpTPaUcsSMjXKxZdwy553Ti2fXrU+sg G+2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=+lpJWKq20JIq4WnucpB3buAw80qtVxaqHE+QZwovzVw=; b=DJ+5PHqH40+4xI9nmX/kT6SqOkRgoTZrQRh648nW1fqHTvzRkQnUHPABtzDJ1XZtAy SFiHk40SIVal5Rd23855DUI3WDmqlykHLhP7NPBOhOVLB+HxJMYRitcT4XceAeSJp2jG N2HZ9MbP9sk2XXHtZuVMwApNHcHrbsfmHVyrN3Swx3Khan3r/BSZAiEP+HoINzdRcDO5 q/8Nq2oqnIYzYJe4d8YCFrsAu4AIFlrmeiY/yVOnFKqNuCOl+/MEe2Z7dTdtqUlxK4Mx Ammsz8pSQMmB3Th7qND2uNqyayiYa30PMB6WmwycnkWZGtMLQHcQLwUm5ZHz7bWCM9Z7 rPNQ== 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 k17si13950642eds.353.2020.08.18.05.48.50; Tue, 18 Aug 2020 05:49:14 -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 S1726784AbgHRMr5 (ORCPT + 99 others); Tue, 18 Aug 2020 08:47:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:48308 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726635AbgHRMr4 (ORCPT ); Tue, 18 Aug 2020 08:47:56 -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 69CAAAD60; Tue, 18 Aug 2020 12:48:19 +0000 (UTC) From: Coly Li To: 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 , "David S . Miller" , Hannes Reinecke , Ilya Dryomov , Jan Kara , Jeff Layton , Jens Axboe , Lee Duncan , Mike Christie , Mikhail Skorzhinskii , Philipp Reisner , Sagi Grimberg , stable@vger.kernel.org, Vasily Averin , Vlastimil Babka Subject: [PATCH v6 0/6] Introduce sendpage_ok() to detect misused sendpage in network related drivers Date: Tue, 18 Aug 2020 20:47:30 +0800 Message-Id: <20200818124736.5790-1-colyli@suse.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series was original by a bug fix in nvme-over-tcp driver which only checked whether a page was allocated from slab allcoator, but forgot to check its page_count: The page handled by sendpage should be neither a Slab page nor 0 page_count page. 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 zero copy sendpage method in network layer. The first patch in this series introduces sendpage_ok() in header file include/linux/net.h, the second patch fixes the page checking issue in nvme-over-tcp driver, the third patch adds page_count check by using sendpage_ok() in do_tcp_sendpages() as Eric Dumazet suggested, and all rested 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: 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: stable@vger.kernel.org Cc: Vasily Averin Cc: Vlastimil Babka --- Changelog: v6: fix page check in do_tcp_sendpages(), and 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. v3, introduce a more common sendpage_ok() v2, fix typo in patch subject v1, the initial version. Coly Li (6): net: introduce helper sendpage_ok() in include/linux/net.h 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 ++- 6 files changed, 24 insertions(+), 8 deletions(-) -- 2.26.2