Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 9FD223815D5; Thu, 20 Aug 2026 15:19:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787239162; cv=none; b=BmVQLL+rTTNSEcJh57qGRSW/UYOw2wLQ8w6W5hN5fI8u1qS2QVDto1jun2cgSvv4p0YjHN7gGZrhzcqyO6O3CnSpByjR4P0nIJUp5YWoMLX/0A6vC8uqDzpcVrTTR7V16VHm4lI8N3UP2mR0dtOddSYcdc8isYJADR1KIHaosfs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787239162; c=relaxed/simple; bh=QKgSCG0w28ED3oIc+zbZLz9Pttemjb7MZwkwLoBt6lQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ceIVXt0S00v3o4Y3HEvwjS8YxfzxrVUsSEgkuiQ5BmK4dKr6kjYKYw9CgnP30Sr+57PU5vyAG6MOppq3ajP41xta3cZ9HMGcjn31HqrxDwoKjNGArZRML6fOK+OvxdRujLlYttOfkJjhUtnyr6TtIj7dYuQ1f8AvKo8iQtIseWo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YNB8auwm; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="YNB8auwm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C24C11F000E9; Thu, 20 Aug 2026 15:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787239161; bh=EM8ISIbiV7MFXy2XvC+EjqdYpZmbg83CK0DY1ASEpCw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YNB8auwmh3fntYD7rASX1mYsVcdnX7K0NbKNaGyHk4VAfpuWcoe/AT4s2+L2fGIpz FjQXHtzsOe6QbncvByxdUYRH1oRPnQLDd4cQwns87IayD+1dYuBYCPp4XOJdUXLr9w /asSYKq/331s9MsulujvWnoKQ8GElxkUOCe/X9xQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ralf Lici , Antonio Quartulli , Sasha Levin Subject: [PATCH 6.18 172/217] ovpn: fix NULL dereference when killing missing key Date: Thu, 20 Aug 2026 16:55:40 +0200 Message-ID: <20260820145242.916451991@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260820145237.531699751@linuxfoundation.org> References: <20260820145237.531699751@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ralf Lici [ Upstream commit 41d44ac7a61e2f74453af40d4fe1b82af9ea0ada ] ovpn_crypto_kill_key assumes both crypto slots are populated and dereferences each slot before checking it. That is not guaranteed: a peer can have only one installed key, and the kill path may be asked to remove a key that is not present. Read each slot once while holding the crypto state lock, check for NULL before looking at key_id, and only replace the slot that actually matches. Fixes: 89d3c0e4612a ("ovpn: kill key and notify userspace in case of IV exhaustion") Signed-off-by: Ralf Lici Signed-off-by: Antonio Quartulli Signed-off-by: Sasha Levin --- drivers/net/ovpn/crypto.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/net/ovpn/crypto.c b/drivers/net/ovpn/crypto.c index 90580e32052fb..2e95f29514fc4 100644 --- a/drivers/net/ovpn/crypto.c +++ b/drivers/net/ovpn/crypto.c @@ -58,15 +58,19 @@ void ovpn_crypto_state_release(struct ovpn_crypto_state *cs) bool ovpn_crypto_kill_key(struct ovpn_crypto_state *cs, u8 key_id) { struct ovpn_crypto_key_slot *ks = NULL; + struct ovpn_crypto_key_slot *tmp; + int slot = 0; spin_lock_bh(&cs->lock); - if (rcu_access_pointer(cs->slots[0])->key_id == key_id) { - ks = rcu_replace_pointer(cs->slots[0], NULL, - lockdep_is_held(&cs->lock)); - } else if (rcu_access_pointer(cs->slots[1])->key_id == key_id) { - ks = rcu_replace_pointer(cs->slots[1], NULL, - lockdep_is_held(&cs->lock)); + tmp = rcu_access_pointer(cs->slots[slot]); + if (!tmp || tmp->key_id != key_id) { + slot = 1; + tmp = rcu_access_pointer(cs->slots[slot]); } + + if (tmp && tmp->key_id == key_id) + ks = rcu_replace_pointer(cs->slots[slot], NULL, + lockdep_is_held(&cs->lock)); spin_unlock_bh(&cs->lock); if (ks) -- 2.53.0