From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 074A513F016; Tue, 27 Feb 2024 14:12:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709043124; cv=none; b=nzmeuh8S1s631Im66vzFmgRNbK34sbAEo6dFC03EnrXLGpR2TZLDErqZLJRf70l1RQaLtb2ThPAwK97F3vE6vVgkz609V3VvMNU/gOCfWgjoCRtbkMtv5zdbzoVwz7uiCaDiWy+HiLIKw2k0V8Zy0V7hGEEp4d9KyUHKUoXnhM8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709043124; c=relaxed/simple; bh=PXI+p5ppr6XHEo3SZN4lee1hyx6TqcmcWnfhokaX3ik=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fqxUeQ/fhu2S2kAp57TRhX0hR4AK+9N0uzZON2ChN0Ze0mIt+LUGYRJv53dRYKs3vIlYGFsQCBJelZdwC15mboR+2j/snvswuC3HU3sRfgnCrgUFwYsLRUiUlhFjwTaSmniF1KOHqE1ccNUl5BnCTZpBFMW4kj7Cy481sWYKgAc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0NTZSrHL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="0NTZSrHL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85679C433F1; Tue, 27 Feb 2024 14:12:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709043123; bh=PXI+p5ppr6XHEo3SZN4lee1hyx6TqcmcWnfhokaX3ik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0NTZSrHLv8n1mYXHblGS5px46DF0yp0gXL251SD1KOkyGjiU4ApOYQjUksMBvXoLP R+1QBP8ZuIvL54VmLKGdYxbrDgzzAQN+MWUf/cRYQ/6STTR0WoHbubvNPRtwXUNjuQ n60TqKcp4Ghssmkp4MBkS2UU2m0/9zqmPrFH/Vcc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Dumazet , Nicolas Dichtel , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15 215/245] ipv4: properly combine dev_base_seq and ipv4.dev_addr_genid Date: Tue, 27 Feb 2024 14:26:43 +0100 Message-ID: <20240227131622.195048004@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240227131615.098467438@linuxfoundation.org> References: <20240227131615.098467438@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 081a0e3b0d4c061419d3f4679dec9f68725b17e4 ] net->dev_base_seq and ipv4.dev_addr_genid are monotonically increasing. If we XOR their values, we could miss to detect if both values were changed with the same amount. Fixes: 0465277f6b3f ("ipv4: provide addr and netconf dump consistency info") Signed-off-by: Eric Dumazet Cc: Nicolas Dichtel Acked-by: Nicolas Dichtel Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/devinet.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index c511751c2f41a..425dfa8e4fd0a 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -1797,6 +1797,21 @@ static int in_dev_dump_addr(struct in_device *in_dev, struct sk_buff *skb, return err; } +/* Combine dev_addr_genid and dev_base_seq to detect changes. + */ +static u32 inet_base_seq(const struct net *net) +{ + u32 res = atomic_read(&net->ipv4.dev_addr_genid) + + net->dev_base_seq; + + /* Must not return 0 (see nl_dump_check_consistent()). + * Chose a value far away from 0. + */ + if (!res) + res = 0x80000000; + return res; +} + static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) { const struct nlmsghdr *nlh = cb->nlh; @@ -1848,8 +1863,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) idx = 0; head = &tgt_net->dev_index_head[h]; rcu_read_lock(); - cb->seq = atomic_read(&tgt_net->ipv4.dev_addr_genid) ^ - tgt_net->dev_base_seq; + cb->seq = inet_base_seq(tgt_net); hlist_for_each_entry_rcu(dev, head, index_hlist) { if (idx < s_idx) goto cont; @@ -2250,8 +2264,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb, idx = 0; head = &net->dev_index_head[h]; rcu_read_lock(); - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^ - net->dev_base_seq; + cb->seq = inet_base_seq(net); hlist_for_each_entry_rcu(dev, head, index_hlist) { if (idx < s_idx) goto cont; -- 2.43.0