Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1173808pxk; Fri, 25 Sep 2020 08:03:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUPWtq96aL+c4np5CUJaSu3A2v6dB1LXg7qjC+cQgodQHhcxOeZ19oS0pmZRDPbZWbu3Sx X-Received: by 2002:a17:906:edc4:: with SMTP id sb4mr3074728ejb.144.1601046191137; Fri, 25 Sep 2020 08:03:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601046191; cv=none; d=google.com; s=arc-20160816; b=EHd6JYZnUfgn9A0U0VoWm6VTwgDmsBI4Q/03ULMKvuw7m80x9miyPMXRKj4ZSh5k/T AmtRjIRGW8o3QcqAStOnbhbqSXwkXyNLVROAVtZrNdExOU7JWlKN7ClbEpryrKcRtf+p XrO9zOvs5JLaG3nkripcXi3pt1XD2DNUAw95So3jxjHf/aljNyT+XRBT2YXxohyem1vp L8w2+GOp5ph6CUbtiZzzge1K8jA2d6f8st6ngYGMGbQs2XFnybhJAP6pSsXkdDylczCt 0bcjhmxVnr8KddWplrSDU/XyuDfBDjYMGpFokMr53DUN1Vom1WYtGZQgfrTET21m/iF2 GccQ== 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=ZAgoNmzkk2wFGuKLSjaCjyabsJNRgYhBVY3y6A/PNHk=; b=a867Id1R2nnrDqvXsSH5i/a4s/oyzeSpLA909ghELmS8DQoqwRC/JzMWny2bwI4lHw GE6aCBIk4z0bqEfCFyXUFONP74d3+8h9KkxZhbic8Iknmn2f5dhJTdDzEY20JdJ7GWwt E7bC++oc6Eg3xkRrgXMwZadF+BDUkS23FfliDjiiKaM1wO0daAjZCBD+KNA0OViD9g4j VeztCVeTz++4V73CEQaM1ncWjM1eQGhSLDLk+fQi0mOGxxqwFNxgDu6b1ptUVqR304w+ BanKL5xgnCaH8h3b5VROrJANx1UluQuObe0UeodZZrsBVNgYVDko5AgsasqIe7c9nT7M fXcQ== 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 r25si2068363ejx.180.2020.09.25.08.02.45; Fri, 25 Sep 2020 08:03:11 -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 S1729235AbgIYPBl (ORCPT + 99 others); Fri, 25 Sep 2020 11:01:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:33914 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728693AbgIYPBk (ORCPT ); Fri, 25 Sep 2020 11:01:40 -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 AD492B02E; Fri, 25 Sep 2020 15:01:38 +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" , 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 v8 0/7] Introduce sendpage_ok() to detect misused sendpage in network related drivers Date: Fri, 25 Sep 2020 23:01:12 +0800 Message-Id: <20200925150119.112016-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 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 concrete zero-copy sendpage method in network layer. The v8 series has 7 patches, - 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: 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