Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1976057ybl; Thu, 9 Jan 2020 04:57:00 -0800 (PST) X-Google-Smtp-Source: APXvYqwD9JvDsZPFnvncwhknqjEZ9SuusaZz9y/vH4NGv/ied8k9k26VKVrWx2+GKw+PNRHQvQPU X-Received: by 2002:a9d:6301:: with SMTP id q1mr8001003otk.70.1578574620167; Thu, 09 Jan 2020 04:57:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578574620; cv=none; d=google.com; s=arc-20160816; b=z5KPPeerOPxA1u9QsHZWoWTTc2ODQm7jOUrLxklzROGNboldPMIPu299mNItWExr7P ziK47vLFIZPqn23QIIyxBx2o8g20NDRwpgwU2NWAMxCBCDHTDtsv7avgz+Rhk4V7kD4r c/CL2M9jxTvhrRm/+JdgeiiksrtZLzDathIVZdOPGq+d9WMaVj3ZE26nOqm6lwGIBmK6 29CbgTgCbZbzSLrXbIenjGTK8DrLJ2xdDQvRzl0q4hX9gUErX857jYpmZogbZ8SV8tDX KqQ1OHaj34oJJCu8/iy43xxe6ZuRYgbKtMCT7yHfemqfMWJpGXQKsVQsD3es7JQuqytj +qaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XW/jU4nMv4mGFekrAe/bVdVaRHEifMOWCDSe/Rg3qfU=; b=Owt7UCNnZqiaKjMjR4SVV9OZayPVkCAtzaMSkqeqrx70MJou+XQQbsOwAmjx1t+3eH dKgPzy1PQjzXh9UJwWcUc+eYq2FIUsLpxU+zq1GvsUFzMnpBLQyP1B4hUwZIFe0IDmyY zrnmDAoS2G2mPmuA1wPiIfLjcEneh2LJwPt6vM5de0tGEq9t8K5IC1U1VUA56sRdruWp LWZr7npRi57ZvYnWYLDyXYyk8N4KvkJ+JB4iLrMIxu5BiVbd6OuX3WgpEyVXsjlAL9s8 vlDEEKs9dlLDhy1Q5188H4cNRD01pulCnMk0QOaanP8HWU3iHr+kHvbEjfVPaiw4xO0I vPgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=rpbyJddq; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si3552828oih.217.2020.01.09.04.56.48; Thu, 09 Jan 2020 04:57:00 -0800 (PST) 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; dkim=pass header.i=@cloudflare.com header.s=google header.b=rpbyJddq; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730251AbgAIL6q (ORCPT + 99 others); Thu, 9 Jan 2020 06:58:46 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55090 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730248AbgAIL6p (ORCPT ); Thu, 9 Jan 2020 06:58:45 -0500 Received: by mail-wm1-f68.google.com with SMTP id b19so2597191wmj.4 for ; Thu, 09 Jan 2020 03:58:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XW/jU4nMv4mGFekrAe/bVdVaRHEifMOWCDSe/Rg3qfU=; b=rpbyJddq33B9qvSn4dhdc1kg2jDsQ5NECfImsJP0BmRVxX8YUmk+GZcwqJ/9GgwemW SkhY18OP1SxlTsHKFBzzBjzzArXq/PvYW5botlr9MrTX37wAcoZbEusNvNDDoddttatK 20KjUtmfCziPSocV4nL54W0IvoVY7BP+gDu/8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XW/jU4nMv4mGFekrAe/bVdVaRHEifMOWCDSe/Rg3qfU=; b=dq45ktIxIRbUToTfi7KAxMaLdMynXvWe+7GafyrsbO0QBE1VemQUhMVj8XKij08PNa yWJSeFt3PxU2FdrPq+D0XawTZdMp//zhBVBjAa80NuMaXOkgbmY9YNQAY1c4YyWIDrtk jHlYCEoWQGBOzrlViYo0yWfsI/r4iLzzQ3Oi2gq590V7/RInm2ozODo1nYcG1lKwNrb3 oI0IPEqxQcbR246J3SZ2RNEiwtUs16GvAY8U/X22s0Gm8CU1fAhpcu2Z5BhPSZ3sq4Vh a1zmDFAKQeOvSnWghZGBvHt6quv901EtdDA8e+k17/rWFxPAfruT2sxx9Z6vpaLY25b+ Iu7Q== X-Gm-Message-State: APjAAAVKR6BuEN0ij7al75ofb3M8PicAqrM/Wz1lQ+FGTDTSIOf3FKuQ gKp19U6q0hydcg5XamKJ5GQbqCrN298= X-Received: by 2002:a7b:cc14:: with SMTP id f20mr4618431wmh.58.1578571123550; Thu, 09 Jan 2020 03:58:43 -0800 (PST) Received: from localhost.localdomain ([2a06:98c0:1000:8250:cd2c:908b:e15b:9937]) by smtp.gmail.com with ESMTPSA id z124sm2728120wmc.20.2020.01.09.03.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2020 03:58:42 -0800 (PST) From: Lorenz Bauer To: Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Lorenz Bauer , Martin KaFai Lau , Joe Stringer , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: kernel-team@cloudflare.com, edumazet@google.com Subject: [PATCH bpf 0/1] Fix memory leak in helpers dealing with sockets Date: Thu, 9 Jan 2020 11:57:47 +0000 Message-Id: <20200109115749.12283-1-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While rolling out a new BPF based TC classifier I hit a memory leak, which manifests in large numbers of request and time wait sockets not being released. The root cause is that the current BPF helpers dealing with sockets are naive: they assume that sk->sk_flags is always valid. struct request_sock and struct inet_timewait_sock break this. I've fixed this up by adding a helper that checks sk_state in addition to sk_flags. The solution is a bit clumsy: it encapsulates details of struct sock in BPF. It would probably be nicer to have a sock_gen_put + SOCK_RCU_FREE function exposed in sock.h, but that might be too big a change for backports. Thoughts? Lorenz Bauer (1): net: bpf: don't leak time wait and request sockets net/core/filter.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) -- 2.20.1