Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2288089imm; Thu, 7 Jun 2018 08:14:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKK9g1L+b6pvdC8mmUmCax8j4OuIVP1Pe6ZZhhU3Y3zwZRaZBCKKErqOX0BkOxYnqiaQY5i X-Received: by 2002:a63:b956:: with SMTP id v22-v6mr1955539pgo.438.1528384446193; Thu, 07 Jun 2018 08:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528384446; cv=none; d=google.com; s=arc-20160816; b=YJXnhG5BAabwQEy/8YFBLx0fzE5TvVMDn8hpjef1hGNCY1I1YUo1J3dhNobQ6MBczl 0YIHsJ8aYyT3qeArkCxaW/HxTYswzpxDK04ACgTuS4VR2zZa1jpEOwhbZZfxVvWMRfPc wO3wYTWQVe+gVl8CjOAFnSzwW1LZW0ecukC5lrRWmfVHYW2bq1IhLrgrnGWkSVeN7eL2 IP1VOHmU0nCbVjo4tIeVEPSlum6zQ8O7B3sIPCHLlD7BPMVERFh2HOMXI5Imh4nGlusL LSZ33sOhO6kx0vu+s81HnmMtR6YpBWJZVzpQS/iJbjkl8dyYGHJVb48JlDIwljjf5yvz QhBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=CKAUFXbBuaik/SvHup9V2eQ5N/E90s2oQHesAZoSzQs=; b=H9Z2NF1GXqd4vuH/cyovXE1p2KXN2cVbMS54o5MC0gmAMkp7OSX9fbBuSvWDNDQRvr mVm+eXXLhBbDHTprLTt5G/7QNckjt0a8bfSfVM+hLg4+H554Q/c0AX1rNsphDxRNrtI9 Rq3PTTlvPg3B1PMwTEAS5i07Ki1DK3FgP07A0JJjfjIuroSrYmtRqp6mQJ5teWNiYFLq dGy8tfj+tIkJCGIDpeAqR0kn5l9X9+ocoaUKdNf6QjLneCuSSoc0TbXwuOR/ie6DBV6z u4P1DXiixN0+c+jXdLf3Wg9Td5bDR+ksjsxIBHEIKzKpPWA+Nv0zlIvAYxDyon7PCJy/ s6Gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1-v6si22560463pln.471.2018.06.07.08.13.51; Thu, 07 Jun 2018 08:14:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964960AbeFGPCu (ORCPT + 99 others); Thu, 7 Jun 2018 11:02:50 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41457 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964940AbeFGPCm (ORCPT ); Thu, 7 Jun 2018 11:02:42 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbS-0005hJ-9Z; Thu, 07 Jun 2018 15:09:26 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvbB-0003C1-Rq; Thu, 07 Jun 2018 15:09:09 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Neil Horman" , "David S. Miller" , "Alexey Kodanev" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 329/410] sch_netem: fix skb leak in netem_enqueue() In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Alexey Kodanev commit 35d889d10b649fda66121891ec05eca88150059d upstream. When we exceed current packets limit and we have more than one segment in the list returned by skb_gso_segment(), netem drops only the first one, skipping the rest, hence kmemleak reports: unreferenced object 0xffff880b5d23b600 (size 1024): comm "softirq", pid 0, jiffies 4384527763 (age 2770.629s) hex dump (first 32 bytes): 00 80 23 5d 0b 88 ff ff 00 00 00 00 00 00 00 00 ..#]............ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<00000000d8a19b9d>] __alloc_skb+0xc9/0x520 [<000000001709b32f>] skb_segment+0x8c8/0x3710 [<00000000c7b9bb88>] tcp_gso_segment+0x331/0x1830 [<00000000c921cba1>] inet_gso_segment+0x476/0x1370 [<000000008b762dd4>] skb_mac_gso_segment+0x1f9/0x510 [<000000002182660a>] __skb_gso_segment+0x1dd/0x620 [<00000000412651b9>] netem_enqueue+0x1536/0x2590 [sch_netem] [<0000000005d3b2a9>] __dev_queue_xmit+0x1167/0x2120 [<00000000fc5f7327>] ip_finish_output2+0x998/0xf00 [<00000000d309e9d3>] ip_output+0x1aa/0x2c0 [<000000007ecbd3a4>] tcp_transmit_skb+0x18db/0x3670 [<0000000042d2a45f>] tcp_write_xmit+0x4d4/0x58c0 [<0000000056a44199>] tcp_tasklet_func+0x3d9/0x540 [<0000000013d06d02>] tasklet_action+0x1ca/0x250 [<00000000fcde0b8b>] __do_softirq+0x1b4/0x5a3 [<00000000e7ed027c>] irq_exit+0x1e2/0x210 Fix it by adding the rest of the segments, if any, to skb 'to_free' list. Add new __qdisc_drop_all() and qdisc_drop_all() functions because they can be useful in the future if we need to drop segmented GSO packets in other places. Fixes: 6071bd1aa13e ("netem: Segment GSO packets on enqueue") Signed-off-by: Alexey Kodanev Acked-by: Neil Horman Signed-off-by: David S. Miller [bwh: Backported to 3.16: - The reshape_fail operation still exists, so keep calling it here if the skb did not require segmentation - We don't have a to_free list, so free directly in qdisc_drop_all() - Open-code qdisc_qstats_drop()] Signed-off-by: Ben Hutchings --- --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -656,6 +656,14 @@ static inline int qdisc_drop(struct sk_b return NET_XMIT_DROP; } +static inline int qdisc_drop_all(struct sk_buff *skb, struct Qdisc *sch) +{ + kfree_skb_list(skb); + sch->qstats.drops++; + + return NET_XMIT_DROP; +} + static inline int qdisc_reshape_fail(struct sk_buff *skb, struct Qdisc *sch) { sch->qstats.drops++; --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -511,8 +511,12 @@ static int netem_enqueue(struct sk_buff 1<<(prandom_u32() % 8); } - if (unlikely(skb_queue_len(&sch->q) >= sch->limit)) + if (unlikely(skb_queue_len(&sch->q) >= sch->limit)) { + /* qdisc_reshape_fail() can't handle segmented skb */ + if (segs) + return qdisc_drop_all(skb, sch); return qdisc_reshape_fail(skb, sch); + } sch->qstats.backlog += qdisc_pkt_len(skb);