From patchwork Fri May 31 13:26:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13681684 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 99E8C158D78 for ; Fri, 31 May 2024 13:26:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162006; cv=none; b=kICrMR1II0A6qaHhK7DJb5qxSYYFMjRvzzjjOAG4whfpdj03i0E04MPuel04HzjG/x7TrSXO07BKTW0y2ALm+ho8MfwaXmK8hZ/ou0fJoQsHwV6/yMkQ/XSONmAWmSA3+maGi/eZ7WRHofeeSZzg9zutr/pFxEbd0JajA0o3dYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162006; c=relaxed/simple; bh=axsyOLYpOtl0YxEdYGMHnEtHTAu+l+pYsDqihrt736I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OjGoiyO2k+2JSrn1GP2N/H4G3R3rbu2t+AS4TpqMRiqYj0J1s62z17fKqWgHCtqMkTzSqlWYY2YxD9dM8dxqt9Kluy6NM7nhaPRbx4P+mzDvoLFZxY4vQDqtpPxrMRvcEywmMVWAxsF77ZXYArZmAH+y2+rygYiaqHPUFKzLKls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dKDlF2j/; arc=none smtp.client-ip=209.85.219.201 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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dKDlF2j/" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfa78a1b142so823992276.1 for ; Fri, 31 May 2024 06:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717162003; x=1717766803; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zrxp3Oe2K9pjE9tLTXKFddbG7yejIdhQMSQxRP/jLo0=; b=dKDlF2j/XORPebnxo8OsnfeCSdqv07l+/NWVy/nikp9zmLw1QOMGqxNK9eDddEi8DL 0DUa7WR48cmgszSVZqCnmLsxF/wTZ5bqLICrXy0eKyyShuLIjq7YFQFd6pvh6WrBdkOi zGcRaGFgdihOxCMHg0RQZ5KjVZP1vIsZ4kPFw5ApTStza6m4LBRwKoGkl7akQVH05tDN v96BHJMo5AWTQ2X6dPdh6TnoseJ4F4cC7zkMWlb6+VDy7tlFFz7rwWCcAX9nXWdXN/io 0j1znJApuKWqTCvkIdAjRwho4Eo4b5WaB3Byrm4uPVx5M0cuOKtpHoLfA65NnZ9gt7rh obNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717162003; x=1717766803; h=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; bh=zrxp3Oe2K9pjE9tLTXKFddbG7yejIdhQMSQxRP/jLo0=; b=qRm4s89GeiQjrlvwcD4/MK9hbGcxLa56iS7V50xs2gjGwCyX6OM6ey2t66H86+V03R Jfdnw54rSp55Y2j9DC1ngLRdBsckXW82PR/ac3LR6/J7oSNHTiUEbSWkoOD2A3BaqZZZ BLFARYWm5LB2MKWrK2upnKzdHca/hUAwz2rJXhRn1irxQz3UgD//QwJu/JZLZwcvj4hh mOOC3pjDQ+ooZVG4v5tZbd3Easina100o1Y6j/925/iLVMhsmV1eE9Ef7YCHexeYMeVz 2T+4M5eVAEOAw7HBN+nar37a4Qi8SAUdsfVAEE5SNptLlfTTxG8aF8fWWrEFILe12IIg w+9w== X-Gm-Message-State: AOJu0Yx9kcGwI1s2+fCIqYAsQgolKWOEP+nPZf3HZKWjRpHIFeDT73ut h4JIZIo5AqqM7P2wBVKG1IAHQB4zj68F+pRiqSH9xtWq59KzTRGxxYmhB23L2xF4akwlitKs9DD lTV/fVlroqQ== X-Google-Smtp-Source: AGHT+IF91IUHjRJVYVh+keDpVURabuBE4/WeBS7u9ymj0OE5liefOe+n6hbZElWOYmoBWB2SJxqidWzDcCUEMA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:1247:b0:dee:6f9d:b753 with SMTP id 3f1490d57ef6-dfa73bfd47fmr83277276.6.1717162003628; Fri, 31 May 2024 06:26:43 -0700 (PDT) Date: Fri, 31 May 2024 13:26:32 +0000 In-Reply-To: <20240531132636.2637995-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240531132636.2637995-1-edumazet@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240531132636.2637995-2-edumazet@google.com> Subject: [PATCH net 1/5] ipv6: ioam: block BH from ioam6_output() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , Justin Iurman X-Patchwork-Delegate: kuba@kernel.org As explained in commit 1378817486d6 ("tipc: block BH before using dst_cache"), net/core/dst_cache.c helpers need to be called with BH disabled. Disabling preemption in ioam6_output() is not good enough, because ioam6_output() is called from process context, lwtunnel_output() only uses rcu_read_lock(). We might be interrupted by a softirq, re-enter ioam6_output() and corrupt dst_cache data structures. Fix the race by using local_bh_disable() instead of preempt_disable(). Fixes: 8cb3bf8bff3c ("ipv6: ioam: Add support for the ip6ip6 encapsulation") Signed-off-by: Eric Dumazet Cc: Justin Iurman --- net/ipv6/ioam6_iptunnel.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv6/ioam6_iptunnel.c b/net/ipv6/ioam6_iptunnel.c index 7563f8c6aa87cf9f7841ee78dcea2a16f60ac344..bf7120ecea1ebe834e70073710be0c1692d7ad1d 100644 --- a/net/ipv6/ioam6_iptunnel.c +++ b/net/ipv6/ioam6_iptunnel.c @@ -351,9 +351,9 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb) goto drop; if (!ipv6_addr_equal(&orig_daddr, &ipv6_hdr(skb)->daddr)) { - preempt_disable(); + local_bh_disable(); dst = dst_cache_get(&ilwt->cache); - preempt_enable(); + local_bh_enable(); if (unlikely(!dst)) { struct ipv6hdr *hdr = ipv6_hdr(skb); @@ -373,9 +373,9 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb) goto drop; } - preempt_disable(); + local_bh_disable(); dst_cache_set_ip6(&ilwt->cache, dst, &fl6.saddr); - preempt_enable(); + local_bh_enable(); } skb_dst_drop(skb); From patchwork Fri May 31 13:26:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13681685 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 22089158DA6 for ; Fri, 31 May 2024 13:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162008; cv=none; b=LH5KzCwWvbagyomYlo5uOTBljJU2lXPmG6OcX7ogAP0UP3BMWIykBKUG91P7XKgU0NjkvmM7NMqB7jbcgQPo4DjQYmj6pcY9dTTySSwXm5N+Urins//EQbDg/2kQHUo6eaVZ+2OU2ueDpXOFpb4RJY46U2R7Z60qqBguLv924aA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162008; c=relaxed/simple; bh=9xG7G/guWrc8yW/F6IygmvmognkE0pf3MKz8308UCng=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kmL50JUAdD9gbcBBHBP17Ry2HVERaSGdz7uGJgudam8CLWebwOCAxPjcpJCAHiTKLx32ct7EWpoaq/W35oi4Er9ig+0r7qji3i9f/Nyfpm/jDQEO663K5myyCMhRt81mfB9rSQdBiMtjDMrb9nSKzd1+jHcb/rQbLsXSg2FGzq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fBv6STtM; arc=none smtp.client-ip=209.85.128.202 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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fBv6STtM" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62a0827391aso37827767b3.1 for ; Fri, 31 May 2024 06:26:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717162005; x=1717766805; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GTb2XObsRXRaPUKTzwO4Gw8CcICzGmzukLxVkK7LUFU=; b=fBv6STtM+/mxXLpRBvdDRIypLtOP/s19WwEcpGlhEvEghldoZB7K/smkJtayA0C/We MHMOr0RtN5BOrX8RwfIyNnkh+GUev3rLAep20qIAuTabNSdmzF238YCcFYVkVTA3TmQD R0mhEAVszZCM94g+Yzmdm2lnXzxNAXX1KcrRWRyduECpWhRkOaSvMrB/AkqDdkjfdhuM j7aLqBLZuJBIUPEJWvdhneREVcFXEG7Cneu7tCxu7yasAWGKMPpYRSnNQ073Y/aImAbR ZGwDPnWLwv8obdM+pc+9Td7fR5DUjLdeXz7d80OkGZJsg/aIdozQXlR0qhBInEOjQjed JI+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717162005; x=1717766805; h=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; bh=GTb2XObsRXRaPUKTzwO4Gw8CcICzGmzukLxVkK7LUFU=; b=UqpLVIIeeQzOLkmoWF1CjjMDmkTNHeskHNVPPrq43I+j5EMwYp8KZa6WrnrQHQC1Zm iN8PRYWPTjBIGElWVXfxKBNlHHWFP4chGDgVGwnxYIgbFwcHbQ6B/DfhWIWGWhFNteWf rQGoW8ofnZj2uSAMOlfSnWg58CAYakru6Cy+k/mf4zNGeBa4/l76vMBqik0q2dDCJkLo htpW1KQIgfvgVOVymMOJlGbHU41bB+kdqj0DRhljx5+Aumc8H4a1N88aerYjw54R8VqL nHzxaBs29I4+R0kcxU7noNJhsw25a9vjYdHvOPwimMyTFKzlCpeMFFIVxn4Z2zxS0DwU ZnHw== X-Gm-Message-State: AOJu0YzJtB0lpDaYfenzupxKyvlaHMTGDlBVqgmhOrck7TB8PKw1T7rB 0gWFO9dI0CMGHHnG+Pg1PCgJo+6kYL5luZcnfAU5yodNYBV9tw5H/zuOUjtkvs1cgm3GtbqulFX NvqHcGzcFJg== X-Google-Smtp-Source: AGHT+IEI8GfmXyFTRNqV22Hr3NSPETpVaf28aCbqtRi7LVIzVKSVIdDRnuagf3feJV42kp3XqMWdXLgs+ETcQw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:690c:f0f:b0:627:a787:abf4 with SMTP id 00721157ae682-62c7964587cmr4680587b3.3.1717162005114; Fri, 31 May 2024 06:26:45 -0700 (PDT) Date: Fri, 31 May 2024 13:26:33 +0000 In-Reply-To: <20240531132636.2637995-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240531132636.2637995-1-edumazet@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240531132636.2637995-3-edumazet@google.com> Subject: [PATCH net 2/5] net: ipv6: rpl_iptunnel: block BH in rpl_output() and rpl_input() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , Alexander Aring X-Patchwork-Delegate: kuba@kernel.org As explained in commit 1378817486d6 ("tipc: block BH before using dst_cache"), net/core/dst_cache.c helpers need to be called with BH disabled. Disabling preemption in rpl_output() is not good enough, because rpl_output() is called from process context, lwtunnel_output() only uses rcu_read_lock(). We might be interrupted by a softirq, re-enter rpl_output() and corrupt dst_cache data structures. Fix the race by using local_bh_disable() instead of preempt_disable(). Apply a similar change in rpl_input(). Signed-off-by: Eric Dumazet Cc: Alexander Aring --- net/ipv6/rpl_iptunnel.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/net/ipv6/rpl_iptunnel.c b/net/ipv6/rpl_iptunnel.c index a013b92cbb860aa36a23f50d3d5c5963857d601c..2c83b7586422ddd2ae877f98e47698410e47b233 100644 --- a/net/ipv6/rpl_iptunnel.c +++ b/net/ipv6/rpl_iptunnel.c @@ -212,9 +212,9 @@ static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb) if (unlikely(err)) goto drop; - preempt_disable(); + local_bh_disable(); dst = dst_cache_get(&rlwt->cache); - preempt_enable(); + local_bh_enable(); if (unlikely(!dst)) { struct ipv6hdr *hdr = ipv6_hdr(skb); @@ -234,9 +234,9 @@ static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb) goto drop; } - preempt_disable(); + local_bh_disable(); dst_cache_set_ip6(&rlwt->cache, dst, &fl6.saddr); - preempt_enable(); + local_bh_enable(); } skb_dst_drop(skb); @@ -268,23 +268,21 @@ static int rpl_input(struct sk_buff *skb) return err; } - preempt_disable(); + local_bh_disable(); dst = dst_cache_get(&rlwt->cache); - preempt_enable(); if (!dst) { ip6_route_input(skb); dst = skb_dst(skb); if (!dst->error) { - preempt_disable(); dst_cache_set_ip6(&rlwt->cache, dst, &ipv6_hdr(skb)->saddr); - preempt_enable(); } } else { skb_dst_drop(skb); skb_dst_set(skb, dst); } + local_bh_enable(); err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); if (unlikely(err)) From patchwork Fri May 31 13:26:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13681686 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 E3E4D158D78 for ; Fri, 31 May 2024 13:26:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162009; cv=none; b=vC7lnDYNwrFJXSt+IgxQORveT99abiqOsMEPR54hETRCrymtYs8FZivbYEGKMtESVUL5xWxmRPnEScAwqNKMpna3tWpeyGJvGkCAjkZBIqX4ZKJw2qjM/CBr9ox4BosAyp8IWNn1SiV8bKqxqcRpVYHbojBWkZlPa7yBOACy82w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162009; c=relaxed/simple; bh=5JX/hgkaAAFc5mPirvL1q/OEzQxWmoDIm+zvMGI7EfU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sbwqtj20lYiJuvrf22BYMZ+ScMx2bN9lfRZCknfuw8IacIIQ7isSCi6baa/hoVXINpEjWAuAWsA2Y3JVuhtb0iai/OezKzkHfZAlj4jUuSThKXqtTYXiREg+/v/ZgdIQ/8TEH2cj/wLCZnjKoZ2/ZJ/NnRvKbY481CsvCg7fxY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pJsXXPY4; arc=none smtp.client-ip=209.85.128.201 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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pJsXXPY4" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-629fe12b380so30418357b3.1 for ; Fri, 31 May 2024 06:26:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717162007; x=1717766807; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4vfcI11qZU7qE+FpTMOhevSJYOshGXKcjG9WxwlWuDU=; b=pJsXXPY44R6Y3O1K/0mDGuOBU3onFHRkzwhjw7PANXtj4wL1zKOCvrn/Ig8eKLpEGU +BgJ4FGFIR+Xk/TB6HZHNf9j0UVuHW/KEZAV9MYauOZSkljI554sGcUNHngUngyMMXBJ b/K5RZFryj7Ya94KNYUR0wHiSVBdkW9oszAFzC9V2gvKSZjBBJbtWh0MXoAaIVHGF7e1 kIBxrqTbYI7+EIz2bH/R/hPoSZlVD7PVlSUxDk06TPc4LzCAMtyfTTde2wmg0rloreX4 w+SFAyIYs4rXzx9FGaZnWsygBhO6DDeErXoHwUMcxj2wC8fzfY8R0aRodOSffKigPFOx WE+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717162007; x=1717766807; h=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; bh=4vfcI11qZU7qE+FpTMOhevSJYOshGXKcjG9WxwlWuDU=; b=GgkdPbua+fvflQzXRpp0d5X20x8NR22DAITZ6rklPp/E+j9YxSa/rN3yfxltWAfpv0 JwqggI1WAXT0rIb9fDHrEhI4XTVTWWo0QF7OPw1kX34DbJvMWurAfUfJGao8XpBrJ3VN y1Oj0mxbWrisCfvl4DpbyFFruG+YaMTnXnfe3UmTDPIheu3dde3T8QVT+1HVi5CMBoh/ 9HFqM90800hzXD7RiELVFl3rc5LeMnehD88XbmvmUPdTcZxwrgXsLeBpHLvvgP2AvCnF IMlc5y60VAESaNNPjhNfFygTNgnZ8BmQH8mZA+fJQD85Hkei0bTlgbXewn3eB5+lSbnK 1pLQ== X-Gm-Message-State: AOJu0YwyQbsHEQEo7fVIbIMIkwbrB7NTW8TEBhes4pkztYAXfsmPcDCj ofuSKkhXgsk4H2IIXCeckWNqTMW20OpRsxiyuq3LeS4nj63WXSxk+MRW/FD8hfar1fP3C+h9YI3 1LN61UQfOeA== X-Google-Smtp-Source: AGHT+IGoiO/2HfvRpHYu0ESN8gknNi7gHRuuQgyGn0D0ja5ORRie+gjEZK2b2v4MmONhZqghufGymr1F9c2KuQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:2f4e:0:b0:dfa:57e8:a37 with SMTP id 3f1490d57ef6-dfa7426ccf7mr95624276.13.1717162006909; Fri, 31 May 2024 06:26:46 -0700 (PDT) Date: Fri, 31 May 2024 13:26:34 +0000 In-Reply-To: <20240531132636.2637995-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240531132636.2637995-1-edumazet@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240531132636.2637995-4-edumazet@google.com> Subject: [PATCH net 3/5] ipv6: sr: block BH in seg6_output_core() and seg6_input_core() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , David Lebrun X-Patchwork-Delegate: kuba@kernel.org As explained in commit 1378817486d6 ("tipc: block BH before using dst_cache"), net/core/dst_cache.c helpers need to be called with BH disabled. Disabling preemption in seg6_output_core() is not good enough, because seg6_output_core() is called from process context, lwtunnel_output() only uses rcu_read_lock(). We might be interrupted by a softirq, re-enter seg6_output_core() and corrupt dst_cache data structures. Fix the race by using local_bh_disable() instead of preempt_disable(). Apply a similar change in seg6_input_core(). Fixes: fa79581ea66c ("ipv6: sr: fix several BUGs when preemption is enabled") Fixes: 6c8702c60b88 ("ipv6: sr: add support for SRH encapsulation and injection with lwtunnels") Signed-off-by: Eric Dumazet Cc: David Lebrun --- net/ipv6/seg6_iptunnel.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c index a75df2ec8db0d369a4e3481576fc09f511a4dd36..098632adc9b5afa69e4b65439ee54c3fc0a8d668 100644 --- a/net/ipv6/seg6_iptunnel.c +++ b/net/ipv6/seg6_iptunnel.c @@ -464,23 +464,21 @@ static int seg6_input_core(struct net *net, struct sock *sk, slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate); - preempt_disable(); + local_bh_disable(); dst = dst_cache_get(&slwt->cache); - preempt_enable(); if (!dst) { ip6_route_input(skb); dst = skb_dst(skb); if (!dst->error) { - preempt_disable(); dst_cache_set_ip6(&slwt->cache, dst, &ipv6_hdr(skb)->saddr); - preempt_enable(); } } else { skb_dst_drop(skb); skb_dst_set(skb, dst); } + local_bh_enable(); err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev)); if (unlikely(err)) @@ -536,9 +534,9 @@ static int seg6_output_core(struct net *net, struct sock *sk, slwt = seg6_lwt_lwtunnel(orig_dst->lwtstate); - preempt_disable(); + local_bh_disable(); dst = dst_cache_get(&slwt->cache); - preempt_enable(); + local_bh_enable(); if (unlikely(!dst)) { struct ipv6hdr *hdr = ipv6_hdr(skb); @@ -558,9 +556,9 @@ static int seg6_output_core(struct net *net, struct sock *sk, goto drop; } - preempt_disable(); + local_bh_disable(); dst_cache_set_ip6(&slwt->cache, dst, &fl6.saddr); - preempt_enable(); + local_bh_enable(); } skb_dst_drop(skb); From patchwork Fri May 31 13:26:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13681687 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 40F58158DB3 for ; Fri, 31 May 2024 13:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162010; cv=none; b=WVT0NuxHC2GGFXZSsuhM8TjSky95/qmIh0sAC2wuJO8XRzeUot7M/tDl/aGmmLaOiu5KTDl+KDuDxcaWXjpDmqefbV2pRR3YrXl3XNFN+u1V8BE1HwlQo2OdEFTE1TBd/LWFJpwfaYoajk1lst3gB7ct7zG7yuKMlcwyaFpIc3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162010; c=relaxed/simple; bh=KNlTnkDBsV8nziMJssQejEN4CWcO3HAPYGm6FmYv+mQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=od/qUhhq6cH7R2DMkz54EKzY3Hjcx6nJ1+sLpQvcN18lUom/hkWbnic6rdZTIcs/hZy+cs2UdiC0ARi+6m9ZlAB95kWzLQFabul36EZDWdELMEtdoSwWTfL8c2t7I+em/rd6SDyRDVmgR9WzI4iNgl7NAXozkcy/Vg9l/eSYyMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sQgvjYmB; arc=none smtp.client-ip=209.85.219.202 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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sQgvjYmB" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-df78ea30f83so2736079276.1 for ; Fri, 31 May 2024 06:26:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717162008; x=1717766808; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=AzFv+SY48LLgj1OhmZZl89i+z/6akG2XkDSwK7PQQZw=; b=sQgvjYmBjBqKmdIBZ1MlUcEMzEkIxohoMH9+3UDNpSToLHmv1lk+pgoqzRJHdSOUk7 Ox/DPWlCum8gSmCl8cogKuYbsL8usjx60FkbsF9t6UdMz8ak8IS32NXP/SnOZYazW0ed XDFbxOdg5/lUzEkVuOQPkC/npLotPuSN6Sj8BVQTvXblft0Cm8GqZdzI6SwiaYfTwMNN /PVUkMkxfPYg2oX2IhDKvJUO8sRP+b3UlsPopj5qIQZ8EO37vxbCrWuSZyWqfNZ1Zowi WIyRMAEZYVGk3FHxsVz548dq9xVHUfT8FIi6RNdcHrYvzUh6KYzpW9c9eu2Bc0Q7rmlN a39g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717162008; x=1717766808; h=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; bh=AzFv+SY48LLgj1OhmZZl89i+z/6akG2XkDSwK7PQQZw=; b=IiRh6qOuchBFxFN0+bAuQdkTpgddceDqws6+Bk1GaV8+d4BWEAqHcZvlitqvtzUiqf FGcI+x86a4MEM1bP92bDUViFb3rYIN42pn9Z4p1f86svkVkGynL8Xze330ebOE4qTIKo 29j88jBguzL6yeMvkq4dcTnE0aGl3nn98t6I4vj/JSkjBdhnM9LnKZw5Fg3Do3SY3J+p o+Mni/OrM7ePjdBAgQFE9VoS+7tkawYMcSU67thWE6zq13l4CpQocl0ZM/nYGiWVyQZr +LNp9+wDcxqRNGx6Ux37wnYh3TGlgw8MesQcfWnJVhqjFBmh5ZuMMjxySJhpINpUQU5A x3BA== X-Gm-Message-State: AOJu0Yye1ow7met0CqHuX/fO2uEkbxP3JlLomsAa/sTokPgZDRRoPl2M KkPQjAUgzm30UorQ7cP4I+qiTHKqVf61BB/zfnUFtzRcdmF507k3sXqkK8XaCvw6nObqbKL1iOK tobLy4ED2/g== X-Google-Smtp-Source: AGHT+IFalLzplnnJL52I7m1bChpSBsJ/77O2b9YIWRnTCvpatWW5AsMR+gMyLoou/J/0NQF414B7AN4rAgIieA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:7493:0:b0:dfa:79ab:d5b6 with SMTP id 3f1490d57ef6-dfa79abd71fmr242435276.1.1717162008298; Fri, 31 May 2024 06:26:48 -0700 (PDT) Date: Fri, 31 May 2024 13:26:35 +0000 In-Reply-To: <20240531132636.2637995-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240531132636.2637995-1-edumazet@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240531132636.2637995-5-edumazet@google.com> Subject: [PATCH net 4/5] ila: block BH in ila_output() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org As explained in commit 1378817486d6 ("tipc: block BH before using dst_cache"), net/core/dst_cache.c helpers need to be called with BH disabled. ila_output() is called from lwtunnel_output() possibly from process context, and under rcu_read_lock(). We might be interrupted by a softirq, re-enter ila_output() and corrupt dst_cache data structures. Fix the race by using local_bh_disable(). Signed-off-by: Eric Dumazet --- net/ipv6/ila/ila_lwt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/ipv6/ila/ila_lwt.c b/net/ipv6/ila/ila_lwt.c index 0601bad798221389fe83318fbb17f192cec880d4..ff7e734e335b06f03c4c8815163a706136e42a3e 100644 --- a/net/ipv6/ila/ila_lwt.c +++ b/net/ipv6/ila/ila_lwt.c @@ -58,7 +58,9 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb) return orig_dst->lwtstate->orig_output(net, sk, skb); } + local_bh_disable(); dst = dst_cache_get(&ilwt->dst_cache); + local_bh_enable(); if (unlikely(!dst)) { struct ipv6hdr *ip6h = ipv6_hdr(skb); struct flowi6 fl6; @@ -86,8 +88,11 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb) goto drop; } - if (ilwt->connected) + if (ilwt->connected) { + local_bh_disable(); dst_cache_set_ip6(&ilwt->dst_cache, dst, &fl6.saddr); + local_bh_enable(); + } } skb_dst_set(skb, dst); From patchwork Fri May 31 13:26:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13681688 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 C8785158DDC for ; Fri, 31 May 2024 13:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162013; cv=none; b=kxQWDDgneSLLvMrbRQqKOXGP4SSshnojnnJpHolsNr7jEE1/xB33aipqaOHILAjf9UYzm532bjUPoDvkOKXMFVrNCw4OYKz9ft6/UYVvrw27ECUp/yNmx64qT7s6awajJuNSeir0lstUkzjssl0MuZbi6NTWCgEqyW6X3GZni6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717162013; c=relaxed/simple; bh=S7Ez0x/plhpNBOQHackP9m2qwmb/z6nZyGyoGelixuE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=us+yhX7HV2JlhGpGWMKodYjZVOPn6Bl/sDw54eqJH+eaXbC15Fsl2L7HM2fAB/nz9pdkcEVWXJ7/t9BMzduDnxeOeN/LzDmA1BV4emEekZEp0aLojW7gqRdRlVv0qQcdn5lQsv4waXx9kIrLpU/jf+NxodBLxPkRxqBjQ5vVoeg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B+uxIFp4; arc=none smtp.client-ip=209.85.219.201 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--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B+uxIFp4" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfa7464759cso1038171276.0 for ; Fri, 31 May 2024 06:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717162011; x=1717766811; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=q6h/URa9gK6v6WpLVrHOMrZgQ0nFMWE+/WiPoMgIwXU=; b=B+uxIFp4579ADy9EszHbf61CnSC7K+Cr22fKyGNoRkZm8Dkvv3xmGDyC738j9cwXm0 +qCuwvHfe/nZQ6sFJRud3YJBNdwzEOOV5GbyRIZMvNVj0Rs4MSIqrDpengRqcHR2IoD+ 2fUSrnK5Uva/tu5JAuV/u+jkUNgqhY2RZRLFgSBG1/vHJf/C7T7TQ5chJC22yigtyqps bEtoEKq7upDjei792zrP4cHl3uwFQTdSKevTytMI5VL0E5OkQsr/SQ4DDdUSkPwVX3f2 BCrRkMswlEEqFWRiypipHtWvotVJOZFDSTEzKs+LvWlkZYC3HiG9UikmqkYCfSxSbfes XUtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717162011; x=1717766811; h=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; bh=q6h/URa9gK6v6WpLVrHOMrZgQ0nFMWE+/WiPoMgIwXU=; b=rWdItmgGfcNgubZuotQn/OkntbHcmH6A7ECuYJXD7dLokhDxjzhlNClJWMmWHoboTY RLieCpLSrtftjw/L+4JiKSEsSlU5CaAdTbPbprxL9RHG4KUiqj/Qpcq3iQTNAQmj9QoV wHyYmUJWgyicNWhCu90Zei8XCYbPokznakH0tS0z5S2c/MUCwtZKLj0aNcdhhsgJ81Yb PNT4ZzcJgmKQ5mARNrGOfgDLnpbGaxo8IMB7M2nvViNS1yY2qn39e6hkHf6SN88Bc7fd HSPqTT3xjfvENbtqVeTyh/ct3LVUCibGoaBjRFwtnyJisN3JPLV7/ib1KnjdayVkpTHx /arw== X-Gm-Message-State: AOJu0YxlXLHiD3oTTTuPYkXuS/+Dhk3eb8AuPJnuzuMidWUZUoV2Nys2 D10IHy2TiPzOaFcwtjP/G2yxQWNfC8bUieQ5XnqhYxuPSFjOqBkcseMX+v2sIiCPsrFlgIoPDCu BDDQASAQZqg== X-Google-Smtp-Source: AGHT+IFTNisGR56JV++aSTSk+8T6k4GBzTke99E5yMKE9thDdLSZrvpI/Ipy1Dfndt+zJP5fs7G6rtI7GVi/Pw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6902:2b85:b0:df4:920f:3192 with SMTP id 3f1490d57ef6-dfa73da3c27mr139462276.8.1717162010983; Fri, 31 May 2024 06:26:50 -0700 (PDT) Date: Fri, 31 May 2024 13:26:36 +0000 In-Reply-To: <20240531132636.2637995-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240531132636.2637995-1-edumazet@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240531132636.2637995-6-edumazet@google.com> Subject: [PATCH net 5/5] net: dst_cache: add two DEBUG_NET warnings From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org After fixing four different bugs involving dst_cache users, it might be worth adding a check about BH being blocked by dst_cache callers. DEBUG_NET_WARN_ON_ONCE(!in_softirq()); It is not fatal, if we missed valid case where no BH deadlock is to be feared, we might change this. Signed-off-by: Eric Dumazet --- net/core/dst_cache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/dst_cache.c b/net/core/dst_cache.c index 6a0482e676d379f1f9bffdda51c7535243b3ec38..70c634b9e7b02300188582a1634d5977838db132 100644 --- a/net/core/dst_cache.c +++ b/net/core/dst_cache.c @@ -27,6 +27,7 @@ struct dst_cache_pcpu { static void dst_cache_per_cpu_dst_set(struct dst_cache_pcpu *dst_cache, struct dst_entry *dst, u32 cookie) { + DEBUG_NET_WARN_ON_ONCE(!in_softirq()); dst_release(dst_cache->dst); if (dst) dst_hold(dst); @@ -40,6 +41,7 @@ static struct dst_entry *dst_cache_per_cpu_get(struct dst_cache *dst_cache, { struct dst_entry *dst; + DEBUG_NET_WARN_ON_ONCE(!in_softirq()); dst = idst->dst; if (!dst) goto fail;