From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9FBF23E25B for ; Tue, 11 Aug 2026 02:45:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786416312; cv=none; b=TfY6HYZ+bNrC3bAsFKXxXsJ2/Q/FQcyX5DGpbzzXWXJ+cfCEkrDGAIAJJsiIJtoiueHaCaR+T/owIXTognwtIFZsDdPJpPxQAD102Y8CBgNBrvElcqEWJBdWFaDielC98ev5wxFgxYgg/4q7JRkOTLIkkneJx0ea4bAxfn6jjMU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786416312; c=relaxed/simple; bh=yn5s9xE1xDD3NjH8SO6qW54Txobg24R4n0g8viFk+2Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=f6ryJJr5K9wzDhUbnWggprVp4Q4FPIYDlwLr1USIWYwiNMt0I/rQeykuD2AUF1Xt0TO+qCmYFxxECa5D1qXk5bOEDyWz+JEn34MLavemYHMOqwX+QM5epwTYlsUAATYUW5WNVXS75KwTMk7wGsPIdtLekolPlPxOgdmSd84Nx0Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mcNwZHOz; arc=none smtp.client-ip=209.85.215.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mcNwZHOz" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cab3e9cd922so1799432a12.0 for ; Mon, 10 Aug 2026 19:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786416300; x=1787021100; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=JG8hvLKVYlkGQJclXs7QzmencZ29P2O6bBbsJPdcu3I=; b=mcNwZHOzd0JKVtpRf4dxBWv8ETm127mO6gAn+gsPdh9FCgmMki18Ga8GxiEl5NjHz7 L3tB33MbR55IJoE4zOVojC4++yAttnk5HcDYUFB39pp2hD5qDi8fGpf2q7fN0DDwxdAl djdAcyndW9inx9gEngAIx9QkpEmA2YxDoHchAGi54CZ09cjSKjI/l6WYI8R6lpIMzNDx qIjtwuNDRxUxwPrlX1pkIkDYMuGVsk1hYyn2X2OE7g15RbkArXnUYrUMT1yICe+6s3hG TudhDMxq+E4UYk+1ABjo6mpyFXTugfeu36z5pbumvMd3cQ2DpdOFa+xQG4SxfyJW2+2H OkYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786416300; x=1787021100; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JG8hvLKVYlkGQJclXs7QzmencZ29P2O6bBbsJPdcu3I=; b=g1xHxm61w/V7h3LY9ClQoiOTIBtZWK4FZZDLdWCTCEmieDFlisK3DpMwrMN+Vx0g3s AkDpZjQUhg1rDMq5VeRxkok4N6x1B3dKFx8rb8R7yBCO+nLdYzJoU0mbGWeEEDPOBNii L5yUDFnRZkz2Wcd5/Dw9TwHC0t8O49UF0ImdyuMgqeHhsJlJn9GYTiJ9a1sq2PALFKgw rvVXeVp4k/uG0ppAN+B9+Nkej5XRAU/YqgU7MHUgvDjlBNPwmWLXzui6BchBLA3zAnHY FL/DvcOr3i7pdBG3JcYmvHjfrc/xV4FICjMrQNqyvxJctUbV1GyMbMLMVOVZE8Vvos1O M56Q== X-Forwarded-Encrypted: i=1; AHgh+RpKPZ6y2coE7KKAx51umvBKOl4sghxgCBRW9KXhZlngBddpl+GqzBr7Ms02eSHtKRou5El/7kdE9xJTAZ8=@vger.kernel.org X-Gm-Message-State: AOJu0YyvIcM1QdfHSIkKzCPyKSanJLZcD6n3eP/PTZL9iK/XwUBGHGlW +P9MdR+G2jIFGpESSRKCHrIGQdEenCglWoywjJMMPuBkGQA6f9ylPIo1KUwtmQjtxBhlCObu+dU ktI13Yg== X-Received: from pgch14.prod.google.com ([2002:a05:6a02:508e:b0:ca7:7de:194]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3992:b0:3bf:6237:4d49 with SMTP id adf61e73a8af0-3cc2baf926bmr409649637.23.1786416299972; Mon, 10 Aug 2026 19:44:59 -0700 (PDT) Date: Tue, 11 Aug 2026 02:43:49 +0000 In-Reply-To: <20260811022012.5416-1-a0yami@mailbox.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260811022012.5416-1-a0yami@mailbox.org> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260811024459.139352-1-kuniyu@google.com> Subject: Re: [PATCH net v3] gtp: serialize PDP context updates From: Kuniyuki Iwashima To: a0yami@mailbox.org Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, horms@kernel.org, kuba@kernel.org, laforge@gnumonks.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, osmocom-net-gprs@lists.osmocom.org, pabeni@redhat.com, pablo@netfilter.org Content-Type: text/plain; charset="UTF-8" From: Qing Ming Date: Tue, 11 Aug 2026 10:20:12 +0800 > PDP contexts can be deleted through GTP_CMD_DELPDP or while the GTP > network device is being unregistered. The latter is serialized by RTNL, > but the generic-netlink delete path only holds RCU. > > Running both paths concurrently can therefore make both paths delete the > same PDP context. The issue was found through static analysis and > reproduced on a KASAN-enabled kernel by a two-thread program > racing GTP_CMD_DELPDP against RTM_DELLINK: > > Oops: general protection fault, probably for non-canonical address > KASAN: maybe wild-memory-access in range > [0xdead000000000120-0xdead000000000127] > RIP: gtp_genl_del_pdp+0x1c1/0x420 [gtp] > RBP: dead000000000122 > > The second deletion dereferenced the poisoned hlist pprev pointer. > > Serialize PDP context updates with a mutex shared by gtp_pdp_add(), > gtp_genl_del_pdp(), and gtp_dellink(). > > Fixes: 459aa660eb1d ("gtp: add initial driver for datapath of GPRS Tunneling Protocol (GTP-U)") > Assisted-by: Codex:gpt-5 > Signed-off-by: Qing Ming > --- > v3: > - Rebase onto net/main. > > v2: https://lore.kernel.org/netdev/20260808124322.5800-1-a0yami@mailbox.org/ > - Use a dedicated mutex instead of RTNL. > - Protect PDP add, delete, and link teardown with the same mutex. > > drivers/net/gtp.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c > index 9a12cc53da00..8ee516debeed 100644 > --- a/drivers/net/gtp.c > +++ b/drivers/net/gtp.c > @@ -12,6 +12,7 @@ > #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt > > #include > +#include > #include > #include > #include > @@ -108,6 +109,7 @@ struct gtp_net { > }; > > static u32 gtp_h_initval; > +static DEFINE_MUTEX(gtp_pdp_lock); > > static struct genl_family gtp_genl_family; > > @@ -1555,9 +1557,11 @@ static void gtp_dellink(struct net_device *dev, struct list_head *head) > struct pdp_ctx *pctx; > int i; > > + mutex_lock(>p_pdp_lock); > for (i = 0; i < gtp->hash_size; i++) > hlist_for_each_entry_safe(pctx, next, >p->tid_hash[i], hlist_tid) > pdp_context_delete(pctx); > + mutex_unlock(>p_pdp_lock); > > list_del(>p->list); > unregister_netdevice_queue(dev, head); > @@ -1833,6 +1837,8 @@ static struct pdp_ctx *gtp_pdp_add(struct gtp_dev *gtp, struct sock *sk, > __be32 ms_addr; > int family; > > + guard(mutex)(>p_pdp_lock); > + Please use the plain mutex_lock() / mutex_unlock(). ---8<--- $ cat Documentation/process/maintainer-netdev.rst ... Using device-managed and cleanup.h constructs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Netdev remains skeptical about promises of all "auto-cleanup" APIs, including even ``devm_`` helpers, historically. They are not the preferred style of implementation, merely an acceptable one. Use of ``guard()`` is discouraged within any function longer than 20 lines, ``scoped_guard()`` is considered more readable. Using normal lock/unlock is still (weakly) preferred. ---8<---