Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp577373rdb; Mon, 15 Jan 2024 06:53:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGkVFcSIWWHizQsbXjoTvafyxqbchBiHG1F/6H9BTzMWKz03dYhfu5dbNwXJIlYB2b+2Ni X-Received: by 2002:a17:906:1b58:b0:a28:e2b7:1ba4 with SMTP id p24-20020a1709061b5800b00a28e2b71ba4mr2571055ejg.9.1705330381991; Mon, 15 Jan 2024 06:53:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705330381; cv=none; d=google.com; s=arc-20160816; b=g+gzCj8MKOGkQBCgV0TGzQodUe3q+c+fh+AlfVMqWNCTk9Zyk+8wwYd4KgPcgrzOGH fyg+m2Q/P33aR7Rvozc0VXhwA8G6PxNlcD86I4+Y96RAkn4r030bs8cvxD83bnfXDvd7 9D6DFep90QxQmkqZ6jUPavYCIczH0V1BcuisbGhoRYgyOM5YDw8fnxrbN0GkqxEGhObI Ba3UHowIhoTaMbR2TTnZQF8RGrE5YYo5IVPbz3xfpMHD0BUFxaSB0cPsV1lLmM2eNHJ8 8H9P3XUmjhsDNeDbhvONEmoQ+c1rEoK+dx8CRFwfGb8Gm2zb4H6/4vRaAO0pYESBPoL4 ZYvg== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=sWlH1sq1XL6/qvGW4ObGIQ0ig9XJfIHmloLxhlTa9x4=; fh=aABwzMYuq85yOQn2pbc6XhDhecLu5/X+HM+ifD3nFdo=; b=dsZTk+wU8w+trnb7YkUyPAbGKvFo4H1EOyX1P/SSlf+iZkJUtsklrxQDCvr8HlUENp d+5wddjifGaZ6Bt3Nas2e9AsfHn0+LqVf7Op1XlZ0wrX3Ik4ANMFTs6QTR7QfZpVzx7p NAchcJBH5zhMPsT/KGrHtfAuSWGSSDJJi/4jFj8Ll6d9UnztPzIndoHF9RyZ/UIs9ktI yM/PBmxc1NIyJBLJ3gEkXWYih+QjXhPWzWuPJnF30uzoOD2IsJ2GDmn5uCrYEbTDZB+N zd04yfzAqtJ/fnYU3Tlf4THtlKJe34mttuKUknIQKZKz9QIijwAdwawIGUlNlxnaDUXy eUYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=I69u5SBk; spf=pass (google.com: domain of linux-kernel+bounces-26143-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26143-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c2-20020a17090603c200b00a2c840217f7si3547505eja.834.2024.01.15.06.53.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:53:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26143-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=@ispras.ru header.s=default header.b=I69u5SBk; spf=pass (google.com: domain of linux-kernel+bounces-26143-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26143-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru 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 A4A991F22710 for ; Mon, 15 Jan 2024 14:53:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE30E17C98; Mon, 15 Jan 2024 14:49:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="I69u5SBk" Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51B891944C; Mon, 15 Jan 2024 14:49:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Received: from localhost.ispras.ru (unknown [10.10.165.8]) by mail.ispras.ru (Postfix) with ESMTPSA id 6DC2A40701F0; Mon, 15 Jan 2024 14:39:33 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 6DC2A40701F0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1705329574; bh=sWlH1sq1XL6/qvGW4ObGIQ0ig9XJfIHmloLxhlTa9x4=; h=From:To:Cc:Subject:Date:From; b=I69u5SBkSzoEghEVZ7NpbEC8mwIYb8wqYUtophEfrKSim2fqnxkXjC7bmsUJEzbMg S2i9HtaXe5TS5hQfLPoZBbrTGnnKdYl2k7Tfn+kEvFAVFN0NJnJlMKg0Trv5QJ0L3C pMY3aOQTkwPEsh1eIKMy9xXKfeLEvccjSy1MSmCg= From: Fedor Pchelkin To: Simon Horman , Julian Anastasov Cc: Fedor Pchelkin , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Dwip Banerjee , netdev@vger.kernel.org, lvs-devel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org Subject: [PATCH net] net: ipvs: avoid stat macros calls from preemptible context Date: Mon, 15 Jan 2024 17:39:22 +0300 Message-ID: <20240115143923.31243-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Inside decrement_ttl() upon discovering that the packet ttl has exceeded, __IP_INC_STATS and __IP6_INC_STATS macros can be called from preemptible context having the following backtrace: check_preemption_disabled: 48 callbacks suppressed BUG: using __this_cpu_add() in preemptible [00000000] code: curl/1177 caller is decrement_ttl+0x217/0x830 CPU: 5 PID: 1177 Comm: curl Not tainted 6.7.0+ #34 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 04/01/2014 Call Trace: dump_stack_lvl+0xbd/0xe0 check_preemption_disabled+0xd1/0xe0 decrement_ttl+0x217/0x830 __ip_vs_get_out_rt+0x4e0/0x1ef0 ip_vs_nat_xmit+0x205/0xcd0 ip_vs_in_hook+0x9b1/0x26a0 nf_hook_slow+0xc2/0x210 nf_hook+0x1fb/0x770 __ip_local_out+0x33b/0x640 ip_local_out+0x2a/0x490 __ip_queue_xmit+0x990/0x1d10 __tcp_transmit_skb+0x288b/0x3d10 tcp_connect+0x3466/0x5180 tcp_v4_connect+0x1535/0x1bb0 __inet_stream_connect+0x40d/0x1040 inet_stream_connect+0x57/0xa0 __sys_connect_file+0x162/0x1a0 __sys_connect+0x137/0x160 __x64_sys_connect+0x72/0xb0 do_syscall_64+0x6f/0x140 entry_SYSCALL_64_after_hwframe+0x6e/0x76 RIP: 0033:0x7fe6dbbc34e0 Use the corresponding preemption-aware variants: IP_INC_STATS and IP6_INC_STATS. Found by Linux Verification Center (linuxtesting.org). Fixes: 8d8e20e2d7bb ("ipvs: Decrement ttl") Signed-off-by: Fedor Pchelkin --- net/netfilter/ipvs/ip_vs_xmit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c index 9193e109e6b3..65e0259178da 100644 --- a/net/netfilter/ipvs/ip_vs_xmit.c +++ b/net/netfilter/ipvs/ip_vs_xmit.c @@ -271,7 +271,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, skb->dev = dst->dev; icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0); - __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); + IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS); return false; } @@ -286,7 +286,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, { if (ip_hdr(skb)->ttl <= 1) { /* Tell the sender its packet died... */ - __IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); + IP_INC_STATS(net, IPSTATS_MIB_INHDRERRORS); icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0); return false; } -- 2.43.0