Skip to content

Commit

Permalink
net: add WARN_ONCE in kernel_sendpage() for improper zero-copy send
Browse files Browse the repository at this point in the history
If a page sent into kernel_sendpage() is a slab page or it doesn't have
ref_count, this page is improper to send by the zero copy sendpage()
method. Otherwise such page might be unexpected released in network code
path and causes impredictable panic due to kernel memory management data
structure corruption.

This path adds a WARN_ON() on the sending page before sends it into the
concrete zero-copy sendpage() method, if the page is improper for the
zero-copy sendpage() method, a warning message can be observed before
the consequential unpredictable kernel panic.

This patch does not change existing kernel_sendpage() behavior for the
improper page zero-copy send, it just provides hint warning message for
following potential panic due the kernel memory heap corruption.

Signed-off-by: Coly Li <[email protected]>
Cc: Cong Wang <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Sridhar Samudrala <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Coly Li authored and davem330 committed Oct 2, 2020
1 parent c381b07 commit 7b62d31
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -3638,9 +3638,11 @@ EXPORT_SYMBOL(kernel_getpeername);
int kernel_sendpage(struct socket *sock, struct page *page, int offset,
size_t size, int flags)
{
if (sock->ops->sendpage)
if (sock->ops->sendpage) {
/* Warn in case the improper page to zero-copy send */
WARN_ONCE(!sendpage_ok(page), "improper page for zero-copy send");
return sock->ops->sendpage(sock, page, offset, size, flags);

}
return sock_no_sendpage(sock, page, offset, size, flags);
}
EXPORT_SYMBOL(kernel_sendpage);
Expand Down

0 comments on commit 7b62d31

Please sign in to comment.