[{"id":3678954,"web_url":"http://patchwork.ozlabs.org/comment/3678954/","msgid":"<aeM4ctFJOxAttIrk@chamomile>","list_archive_url":null,"date":"2026-04-18T07:53:22","subject":"Re: [PATCH 2/2 nf] netfilter: nfnetlink_osf: fix potential NULL\n dereference in ttl check","submitter":{"id":1315,"url":"http://patchwork.ozlabs.org/api/people/1315/","name":"Pablo Neira Ayuso","email":"pablo@netfilter.org"},"content":"On Fri, Apr 17, 2026 at 06:20:57PM +0200, Fernando Fernandez Mancera wrote:\n> The nf_osf_ttl() function accessed skb->dev to perform a local interface\n> address lookup without verifying that the device pointer was valid.\n> \n> Additionally, the implementation utilized an in_dev_for_each_ifa_rcu\n> loop to match the packet source address against local interface\n> addresses. It assumed that packets from the same subnet should not see a\n> decrement on the initial TTL. A packet might appear it is from the same\n> subnet but it actually isn't especially in modern environments with\n> containers and virtual switching.\n> \n> Remove the device dereference and interface loop. Replace the logic with\n> a switch statement that evaluates the TTL according to the ttl_check.\n> \n> Fixes: 11eeef41d5f6 (\"netfilter: passive OS fingerprint xtables match\")\n> Reported-by: Kito Xu (veritas501) <hxzene@gmail.com>\n> Closes: https://lore.kernel.org/netfilter-devel/20260414074556.2512750-1-hxzene@gmail.com/\n> Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>\n\nReviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>\n\n> ---\n> Note: if some help is needed during the backport I can assist.\n> ---\n>  net/netfilter/nfnetlink_osf.c | 22 +++++++---------------\n>  1 file changed, 7 insertions(+), 15 deletions(-)\n> \n> diff --git a/net/netfilter/nfnetlink_osf.c b/net/netfilter/nfnetlink_osf.c\n> index f58267986453..f0d1e596e146 100644\n> --- a/net/netfilter/nfnetlink_osf.c\n> +++ b/net/netfilter/nfnetlink_osf.c\n> @@ -31,26 +31,18 @@ EXPORT_SYMBOL_GPL(nf_osf_fingers);\n>  static inline int nf_osf_ttl(const struct sk_buff *skb,\n>  \t\t\t     int ttl_check, unsigned char f_ttl)\n>  {\n> -\tstruct in_device *in_dev = __in_dev_get_rcu(skb->dev);\n>  \tconst struct iphdr *ip = ip_hdr(skb);\n> -\tconst struct in_ifaddr *ifa;\n> -\tint ret = 0;\n>  \n> -\tif (ttl_check == NF_OSF_TTL_TRUE)\n> +\tswitch (ttl_check) {\n> +\tcase NF_OSF_TTL_TRUE:\n>  \t\treturn ip->ttl == f_ttl;\n> -\tif (ttl_check == NF_OSF_TTL_NOCHECK)\n> -\t\treturn 1;\n> -\telse if (ip->ttl <= f_ttl)\n> +\t\tbreak;\n> +\tcase NF_OSF_TTL_NOCHECK:\n>  \t\treturn 1;\n> -\n> -\tin_dev_for_each_ifa_rcu(ifa, in_dev) {\n> -\t\tif (inet_ifa_match(ip->saddr, ifa)) {\n> -\t\t\tret = (ip->ttl == f_ttl);\n> -\t\t\tbreak;\n> -\t\t}\n> +\tcase NF_OSF_TTL_LESS:\n> +\tdefault:\n> +\t\treturn ip->ttl <= f_ttl;\n>  \t}\n> -\n> -\treturn ret;\n>  }\n>  \n>  struct nf_osf_hdr_ctx {\n> -- \n> 2.53.0\n>","headers":{"Return-Path":"\n <netfilter-devel+bounces-12012-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","netfilter-devel@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=netfilter.org header.i=@netfilter.org\n header.a=rsa-sha256 header.s=2025 header.b=ATjZEqTT;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=netfilter-devel+bounces-12012-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org\n header.b=\"ATjZEqTT\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=217.70.190.124","smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=netfilter.org","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=netfilter.org"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fyPBk6Qv8z1yDF\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 17:53:34 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 38C38301B176\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 07:53:32 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 7A00F36C598;\n\tSat, 18 Apr 2026 07:53:30 +0000 (UTC)","from mail.netfilter.org (mail.netfilter.org [217.70.190.124])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id DAB3536EAA5;\n\tSat, 18 Apr 2026 07:53:26 +0000 (UTC)","from netfilter.org (mail-agni [217.70.190.124])\n\tby mail.netfilter.org (Postfix) with UTF8SMTPSA id E56F16026E;\n\tSat, 18 Apr 2026 09:53:24 +0200 (CEST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776498809; cv=none;\n b=VgFqlIP9E5ZMVDrcWegDH3FsCgzN4HarQc2T+aHsWcG5iIH5Hyi7pMRctYlsErvYzkrOrbuhDxXI1HhfqAXy3kEs8X9+dWzhv618Orxv61T8StvJGlv75PI0UPkqTu1z/OX+3GrB/1+/7dAaAhPA/1BVwgCq2KD1FHpG92zFBnc=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776498809; c=relaxed/simple;\n\tbh=6zZ1a+qKZhdClvAuRQmWHwCcbSkt7cijHxe0eO17cBI=;\n\th=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:\n\t Content-Type:Content-Disposition:In-Reply-To;\n b=SRKHTiru5FHRVmLGhT0BvhXyt/nX0IvyJM6M2eSorC6+8WOLivRWBpjiY8UdiOvD2+ujXfWIZpjj8YG4yBE72bmy9JUGlTVBQPaRVOjlrPh0F+82cvZ3t1T/cV5C8vszcFcuiClNJg22TnOBr8WhCRXKgjKJUPzB9KWqIgg+nCo=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=none (p=none dis=none) header.from=netfilter.org;\n spf=pass smtp.mailfrom=netfilter.org;\n dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org\n header.b=ATjZEqTT; arc=none smtp.client-ip=217.70.190.124","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org;\n\ts=2025; t=1776498805;\n\tbh=khR9e0VtESCyMdhpmmjtB0hEbrS9fbM/06QAeE528iw=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ATjZEqTTJhJYx+zU81xTIR6glPBnGfqlX5fQjI92wa0IZSUK6L4ezjLS000h8F8Df\n\t jISXEk17TnyW1QC5oUCQSW35uXQyv22u+cBtj/Q+NsdkjEvrS7iEUPe7viH3YAI1t5\n\t 5dF7p4CzJTRIOHV4DC0VIXvMDcQqnhd2n3TtTw6bh8XOGvp+R00wtGrlcQKUFwqo2M\n\t HzJUZK5oYfANslC6sjpmxY2wNHo6GCGRlKprWd1IProHFFr4HbIoY5GhfmMUqH2RF9\n\t ahJscvvZbrVLoRuMm6jduSnX/ZkwY0WmxZZ7G2QSWHwDZT6Eu01kFtv1ZmMPxDgvaP\n\t tY7LK2KZUtjDQ==","Date":"Sat, 18 Apr 2026 09:53:22 +0200","From":"Pablo Neira Ayuso <pablo@netfilter.org>","To":"Fernando Fernandez Mancera <fmancera@suse.de>","Cc":"netfilter-devel@vger.kernel.org, netdev@vger.kernel.org,\n\tcoreteam@netfilter.org, fw@strlen.de, phil@nwl.cc,\n\t\"Kito Xu (veritas501)\" <hxzene@gmail.com>","Subject":"Re: [PATCH 2/2 nf] netfilter: nfnetlink_osf: fix potential NULL\n dereference in ttl check","Message-ID":"<aeM4ctFJOxAttIrk@chamomile>","References":"<20260417162057.3732-1-fmancera@suse.de>\n <20260417162057.3732-2-fmancera@suse.de>","Precedence":"bulk","X-Mailing-List":"netfilter-devel@vger.kernel.org","List-Id":"<netfilter-devel.vger.kernel.org>","List-Subscribe":"<mailto:netfilter-devel+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:netfilter-devel+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20260417162057.3732-2-fmancera@suse.de>"}}]