From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87C82C43381 for ; Tue, 5 Mar 2019 15:12:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 55A4820684 for ; Tue, 5 Mar 2019 15:12:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bl+3SqVF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728546AbfCEPMA (ORCPT ); Tue, 5 Mar 2019 10:12:00 -0500 Received: from mail-yw1-f65.google.com ([209.85.161.65]:36861 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726190AbfCEPL7 (ORCPT ); Tue, 5 Mar 2019 10:11:59 -0500 Received: by mail-yw1-f65.google.com with SMTP id 189so7196241ywi.3 for ; Tue, 05 Mar 2019 07:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tCdngl/7PhjA5MZYjUpMUEq618SAoNLoDh5Px02VmZo=; b=bl+3SqVFCDruZhLflYmtu9T3NC9RhIOwVe1isgRqqkq9Ew/l0GFaN4unibl3sGTmO0 q3zCGIPdYXEwWbTrzOqb/CN7rZkDnhe/yoiC34JtVMx+rkWwotYFd15OWl+sZWzj02mn E2l/AYK0e3N/g4C5XMkuaROP7RN2u//f0lJfpv7arBSURiEJdeNWVlfSL1i4b3p37l9M BXBnO4tmJrrteMotqfbwT23oy7QQp0skadYl3yLEmLQmO95+ZkAP6eZkz+d04nPiAE16 6l7XyTx8eIjMZlpsjQVv0tmXB2DmNpy5APr+HE0epAAnfhPVPA8ES8N+GD7NN3Nt31Ce 8XlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tCdngl/7PhjA5MZYjUpMUEq618SAoNLoDh5Px02VmZo=; b=U6BymnPasLiIKX2F/cXM8g2yPECjU8w8I0OZL76D560RG3ZYO57AzmAtHCECr5ws+3 uzgWKV4blU7nGy39Iw3LeCplXmb8f5ybagoO3Fgc3l2+Je1ndqsknnRj/h5GO7Tt0J4U kF/C+79G5/Bdtf78/YqoRo8W8+todsOz04a10kc0N2ZAMIGQ+JFbW/kZGL0wddHIPsvR vC7yHFRBCTYR5+0QT7GO4MjHwES5VXR3WK5k4bvj4ty3AnQyDXd7yPGRPiQV1uCds8OK NKTBrZxwW+0zts2R1EJExK3/WuJqCyASz4VeqdAU+NgNAZMiFKwd6Pfo2pbTe9Z2wZl2 giwQ== X-Gm-Message-State: APjAAAVa7W2aafqJsyGFxDr7J5IzlSDPVPOAZvtKptWxfgAczYb3iBMg QFMgHq2S4pWTgxnAvrIrm4GEg7hbd7pgT5zx3pF94w== X-Google-Smtp-Source: APXvYqwMubJzyad1ziCaU4SdOP9QwgbFmYmWuYrTQMXl54HZlQHRP2OWso4XA0lLN6OwXMLVrpI8OmwiNNjcmtmxVp4= X-Received: by 2002:a25:abe6:: with SMTP id v93mr2482616ybi.378.1551798718151; Tue, 05 Mar 2019 07:11:58 -0800 (PST) MIME-Version: 1.0 References: <4a7d3903-971d-26ea-1d70-514abff88f91@virtuozzo.com> <85b6a52f-f997-6fc6-bc5a-99aaeaa27cc5@virtuozzo.com> In-Reply-To: From: Eric Dumazet Date: Tue, 5 Mar 2019 07:11:46 -0800 Message-ID: Subject: Re: [PATCH] tcp: detect use sendpage for slab-based objects To: Vasily Averin Cc: Eric Dumazet , netdev , Al Viro Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Resent in plain text mode for the lists. On Tue, Mar 5, 2019 at 7:08 AM Eric Dumazet wrote: > > > > On Tue, Mar 5, 2019 at 6:24 AM Vasily Averin wrote: >> >> On 3/4/19 6:51 PM, Eric Dumazet wrote: >> > On 03/04/2019 04:58 AM, Vasily Averin wrote: >> >> Eric, what do you think about following patch? >> >> I validate its backported version on RHEL7 based OpenVZ kernel before sending to mainline. >> >> >> >> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c >> >> index cf3c5095c10e..7be7b6abe8b5 100644 >> >> --- a/net/ipv4/tcp.c >> >> +++ b/net/ipv4/tcp.c >> >> @@ -943,6 +943,11 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset, >> >> ssize_t copied; >> >> long timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); >> >> >> >> + if (PageSlab(page)) { >> >> + VM_WARN_ONCE(true, "sendpage should not handle Slab objects," >> >> + " please fix callers\n"); >> >> + return sock_no_sendpage_locked(sk, page, offset, size, flags); >> >> + } >> >> /* Wait for a connection to finish. One exception is TCP Fast Open >> >> * (passive side) where data is allowed to be sent before a connection >> >> * is fully established. >> >> >> > >> > There are at least four problems with this approach : >> > >> > 1) VM_WARN_ONCE() might be a NOP, and if not, it is simply some lines in syslog, >> > among thousands. >> > >> > 2) Falling back will give no incentive for callers to fix their code. >> >> We can return error instead of fallback, >> but yes, it means an extra (almost unneeded) check in TCP code. >> >> > 3) slowing down TCP, just because of some weird kernel-users. >> > I agree to add sanity check for everything user space can think of (aka syzbot), >> > but kernel users need to be fixed, without adding code in TCP. >> >> Do you advise to add PageSlab check into all .sendpage / .sendpacge_locked / >> tcp_sendpage / do_tcp_sednpages callers instead? >> > > > My original suggestion was to use VM_WARN_ONCE() so that the debug checks would > be compiled out by the compiler, unless you compile a debug kernel. > > Something like : > > diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c > index ad07dd71063da09843ccfbd3e00d3f41567e1205..889563a66dde2a41c198d92a80183cf5382f632d 100644 > --- a/net/ipv4/tcp.c > +++ b/net/ipv4/tcp.c > @@ -943,6 +943,9 @@ ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset, > ssize_t copied; > long timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); > > + if (VM_WARN_ONCE(PageSlab(page)), "page must not be a Slab one") > + return -EINVAL; > + > /* Wait for a connection to finish. One exception is TCP Fast Open > * (passive side) where data is allowed to be sent before a connection > * is fully established. > > > For some reason you added a fallback :/ >