[Devel] [PATCH RHEL8 COMMIT] ms/tcp: use sendpage_ok() to detect misused .sendpage

Konstantin Khorenko khorenko at virtuozzo.com
Fri Jun 11 15:33:49 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.40
------>
commit 637a297cb5e49b7b41228c20ebc74498d92619a9
Author: Coly Li <colyli at suse.de>
Date:   Fri Jun 11 15:33:49 2021 +0300

    ms/tcp: use sendpage_ok() to detect misused .sendpage
    
    commit a10674bf2406 ("tcp: detecting the misuse of .sendpage for Slab
    objects") adds the checks for Slab pages, but the pages don't have
    page_count are still missing from the check.
    
    Network layer's sendpage method is not designed to send page_count 0
    pages neither, therefore both PageSlab() and page_count() should be
    both checked for the sending page. This is exactly what sendpage_ok()
    does.
    
    This patch uses sendpage_ok() in do_tcp_sendpages() to detect misused
    .sendpage, to make the code more robust.
    
    mFixes: a10674bf2406 ("tcp: detecting the misuse of .sendpage for Slab objects")
    Suggested-by: Eric Dumazet <eric.dumazet at gmail.com>
    Signed-off-by: Coly Li <colyli at suse.de>
    Cc: Vasily Averin <vvs at virtuozzo.com>
    Cc: David S. Miller <davem at davemloft.net>
    Cc: stable at vger.kernel.org
    Signed-off-by: David S. Miller <davem at davemloft.net>
    
    (cherry-picked from ms cf83a17edeeb ("tcp: use sendpage_ok() to detect misused
    .sendpage"))
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 net/ipv4/tcp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 538d63ca58c5..f8dbf6f14892 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -962,7 +962,8 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
 	long timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);
 
 	if (IS_ENABLED(CONFIG_DEBUG_VM) &&
-	    WARN_ONCE(PageSlab(page), "page must not be a Slab one"))
+	    WARN_ONCE(!sendpage_ok(page),
+		      "page must not be a Slab one and have page_count > 0"))
 		return -EINVAL;
 
 	/* Wait for a connection to finish. One exception is TCP Fast Open


More information about the Devel mailing list