Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1313766lqt; Fri, 7 Jun 2024 14:41:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXaS1gH9NRx7wvlveP/CcVv7yebooPrwj/RpiepVi2G1tj2E2pq+MlmAc5PYj75sbvFy/KsTrtqxJWYchRwZQgZL67C6koV4HJzZxPQ3g== X-Google-Smtp-Source: AGHT+IH70p/jjHzB8dmDKT6SY/VKmXaHmGFRquL/ICGlpqfnoM6+vtBPTMq4SideNxkU3P9bq08Y X-Received: by 2002:a17:906:7aca:b0:a68:ece7:8db5 with SMTP id a640c23a62f3a-a6cd665e55bmr251462466b.31.1717796515120; Fri, 07 Jun 2024 14:41:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717796515; cv=pass; d=google.com; s=arc-20160816; b=g8Ri0VJDBDSweC8Aljq1yh9B7wpYk0g+Fegoi+5Z2mBStn3/Xgew6OvFLDg7mPDWIZ +wm6CgeLquOoTy6i1P5oCiTr/TRpfYUt0+q0+HWentjK5Gv5JL4ogTEqrcyUEfZJ+ClN 4mrpuz14vxtW+fRSnIkWTYYsMLuiBlqi+hWH2TJE3Gyz1ZNBQ62eqw5AzMIMF9P3h5jt zXGF0ouZoQVEPDb82GOUsj8efF08/kWOwigKGb7m5Rr9ozbb7M+Jm70fQZZbzqLI2tmI HavN6+cN+oOo48S/77h33gLlV8XOxf1Ba0EAwBxR6bkbwNX0h9RrJbtri50zidy16/Wl PT4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=M6hr5Pgg5LYV8IvTkAUUqijfPi8ple/giWX7dtweBwU=; fh=+KtnK5iiqsnir/JMMtcYIE2jw2mQTx8nBJPjqm3yOpw=; b=ACEy/w7pXy1Qi6/9w6r3TAoz/YyFSAd9NOGznpcbr6Piq3Wg916q3JCkNW0wmnBYik ITpAcKHt7B3ZYQkGEme2xft+4hG6KpAPK/eVqzZz+wSpKKKlszNvzivOpkL4imDcQDEZ KxHrv3w2an5PZpn1upzA6IijoYMEyiwiYjSvNvWCeZMY9h7gWBrD3lXk6M7nHn1kUmfJ qZ5SPZR/FstWyWBzGlK9TndrtnnI9l220Uf8m7przF8MF4QeK8sTio2e7DoIItpRoR5G jNhVMD/Br+6Mv5WlJGKR3YXQDuPkKc9b9qX9W48yaDoLOwKmNOwmiT0YxbsVcp12tiUL xTFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=Z9DKg3SF; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-206782-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206782-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6efc2133b2si19837866b.164.2024.06.07.14.41.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 14:41:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206782-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=Z9DKg3SF; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-206782-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206782-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CB0961F23839 for ; Fri, 7 Jun 2024 21:41:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15085155A26; Fri, 7 Jun 2024 21:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="Z9DKg3SF" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 E02DC1552F9 for ; Fri, 7 Jun 2024 21:41:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717796480; cv=none; b=MPy3MQBSzCnMMZlQxQkaz3mG4VzvFlysQo1/9/Ih4lRSbYOZFJZfaXyG6AernsI2/Lfjz3bevGrCerVnE1GAGoJEBxFXI/SVQa12xwiPoGuVWkU0zmwSh87jhFTtuhfRWpCcGqNuWpbse6g2zGLTjX/exIKTB3U4Vw3afqAUXH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717796480; c=relaxed/simple; bh=+zDHm0gqEYnNElTfpQqNXDS5sE+4HW2XfxQCpQQCbSE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pyQHtQf02d7HCLiK9d7994oV2xRtwK1dOu5UMmT4AwVERee3vBEfBKeAIUVWkY2NRQ142MbLwCQrYICtx8cslcmOkObl1mNrg+j33WYymt1Zv837JVwbUGnKP/fiBKyw2LmZ5QZ6lgMwDAhlXlvTL4HFWCXc2Mx0BFMUGsRAHU4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=Z9DKg3SF; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1f47f07acd3so24557195ad.0 for ; Fri, 07 Jun 2024 14:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1717796478; x=1718401278; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M6hr5Pgg5LYV8IvTkAUUqijfPi8ple/giWX7dtweBwU=; b=Z9DKg3SFZv5D/L1UQYIGoZFTmyjArQ+DavEzSWG/A77KkhIYYrzIKCXeChJFXL3HrI q0ocBiSI0p7j7VheYjrOKzdy91QRGaZSsGsZF+6Pa05N38HKd1k0NA6l+2MyX5ehLhhh uxYxtc/y64gC8zpMQUhC7YDDSQhWokBTiKfsA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717796478; x=1718401278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M6hr5Pgg5LYV8IvTkAUUqijfPi8ple/giWX7dtweBwU=; b=HIXjVrhgA9qqHxRpy6C1xlPUonTHNbwRKE8iJtkFfcAPOmtN/AsFCNyTaA0qFP+oN/ wvttiJC3UNDZY5IEYR8W66f5GOCrcsT42wzsdRDVe44QwfcJbId4Gb47/Gry9KqgD6W/ APlLirXXwQWYVAtJHALHgTZ7sfKFPJyDzGu5C67cCXYAxc6oCXEJNUbZq/oQZxcx8YQB 5BpttBcck0WmQzacwjkMFA48RtAhsv+l6KrYop/Po1Dm5LKxIzxOK5kYW4rvDbbQeu5w dsrjFX8vifn3Y1bVeMlV2sNJ3eEJjx/v4/nlzZ/ipzMItYxvcKP23QJ26/Hw0yE/GijU ezag== X-Forwarded-Encrypted: i=1; AJvYcCUo8zoQNMu9jO/++1oQfjalqtCdBNZ61Keg5pUAiROghpHBWC5yrswCOK89x0BDUvkwIWDzEfXRT2x3BzW8tjHhNeUZ9VrpNATqOajd X-Gm-Message-State: AOJu0YywyqVi7Kkk9Dji3e33CnDVYNEPyaMGrJqmlYFzML9ji0Ujjv2J PtAn4XJiDChq6MGRXwVS+w7KjTP337EMJTTY3y7np4KnAGvXNnroLoXrB2PfmEdeOTI7ujW97CW L8w== X-Received: by 2002:a17:902:c94f:b0:1f6:8a19:4562 with SMTP id d9443c01a7336-1f6dfc426d6mr27231345ad.24.1717796478156; Fri, 07 Jun 2024 14:41:18 -0700 (PDT) Received: from ubuntu-vm.dhcp.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6bd7e189fsm38946805ad.215.2024.06.07.14.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 14:41:17 -0700 (PDT) From: Kuntal Nayak To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, davem@davemloft.net, kuba@kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, ajay.kaher@broadcom.com, alexey.makhalov@broadcom.com, vasavi.sirnapalli@broadcom.com, Ziyang Xuan , Kuntal Nayak Subject: [PATCH 2/2 v5.10] netfilter: nf_tables: Fix potential data-race in __nft_obj_type_get() Date: Fri, 7 Jun 2024 14:37:35 -0700 Message-Id: <20240607213735.46127-2-kuntal.nayak@broadcom.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240607213735.46127-1-kuntal.nayak@broadcom.com> References: <20240607213735.46127-1-kuntal.nayak@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ziyang Xuan [ upstream commit d78d867dcea69c328db30df665be5be7d0148484 ] nft_unregister_obj() can concurrent with __nft_obj_type_get(), and there is not any protection when iterate over nf_tables_objects list in __nft_obj_type_get(). Therefore, there is potential data-race of nf_tables_objects list entry. Use list_for_each_entry_rcu() to iterate over nf_tables_objects list in __nft_obj_type_get(), and use rcu_read_lock() in the caller nft_obj_type_get() to protect the entire type query process. Fixes: e50092404c1b ("netfilter: nf_tables: add stateful objects") Signed-off-by: Ziyang Xuan Signed-off-by: Pablo Neira Ayuso Signed-off-by: Kuntal Nayak --- net/netfilter/nf_tables_api.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index de56f25dc..f3cb5c920 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -6238,7 +6238,7 @@ static const struct nft_object_type *__nft_obj_type_get(u32 objtype, u8 family) { const struct nft_object_type *type; - list_for_each_entry(type, &nf_tables_objects, list) { + list_for_each_entry_rcu(type, &nf_tables_objects, list) { if (type->family != NFPROTO_UNSPEC && type->family != family) continue; @@ -6254,9 +6254,13 @@ nft_obj_type_get(struct net *net, u32 objtype, u8 family) { const struct nft_object_type *type; + rcu_read_lock(); type = __nft_obj_type_get(objtype, family); - if (type != NULL && try_module_get(type->owner)) + if (type != NULL && try_module_get(type->owner)) { + rcu_read_unlock(); return type; + } + rcu_read_unlock(); lockdep_nfnl_nft_mutex_not_held(); #ifdef CONFIG_MODULES -- 2.39.3