From patchwork Fri Apr 12 20:02:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1923251 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VGSCc699Vz1yYB for ; Sat, 13 Apr 2024 06:02:36 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rvN6S-00033m-3Q; Fri, 12 Apr 2024 20:02:28 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rvN6L-0002yS-Df for kernel-team@lists.ubuntu.com; Fri, 12 Apr 2024 20:02:21 +0000 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 107453F183 for ; Fri, 12 Apr 2024 20:02:21 +0000 (UTC) Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-7d63c6a2559so97806139f.1 for ; Fri, 12 Apr 2024 13:02:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712952139; x=1713556939; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KaEyS6ySvyV32oytHf3JF6O1iZUUurjNR320CAcuC2I=; b=MU6L9mxhlTtksjoC4zv2EYY6JSRVwebzhYJtrROkVIibjv7fe9bhUXV6Vf1DS6Vn9k YCRbBcAaWCSR/Rk1CO7aHQLXQZgbjC7bO2TZnaZyblxELX9Xh6u62iFTeCEncn3zI5Sq UEDkzwszhltZZXMcSr45lQYUCXwWbmP8rVSViURBgHr5aKhDJn94utEnnrGw25Eo/pzb +5JKYg4wDeEIxMi5/rc+7DYellopd0aO9cQR3AOVVDkBzMlTkS7L2VMG5yzn6n0m3VSQ C6EYZfusf3aJABnjFZj5l5qGiSErDuJpT2NzU/oLrhPBii7xU+dPtg15Y4PxPOUoJlU7 xTLA== X-Gm-Message-State: AOJu0YxlFq3VA9MEBLZG9Cy9f4tdtQIYHDLaDvzSTULHmzdyIHkfGAs4 LH99DueYDLqK8yyrGP6HMutrQSpkO/ewFWg8mKAXpInDMj4Cr7Lt/AlD9SRq1xIVPjrkw7iBT0F Ry5mTnhWg5QhZQrWVYbcqN1Fys9Sr+CxcwjGAO3OoStHmxyBmho2Yp9J04kKVjxGm67Lnl0ohKe 2+N6kklTdHkw== X-Received: by 2002:a5e:c818:0:b0:7d6:3864:6ba2 with SMTP id y24-20020a5ec818000000b007d638646ba2mr4890601iol.8.1712952139662; Fri, 12 Apr 2024 13:02:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVEBqzFRESH8LPgzGwdj9/mrgciapQNWmj7u9nqEspjw5IlvQ9nt9b0hhAvK+e8mJ6O62DVg== X-Received: by 2002:a5e:c818:0:b0:7d6:3864:6ba2 with SMTP id y24-20020a5ec818000000b007d638646ba2mr4890595iol.8.1712952139354; Fri, 12 Apr 2024 13:02:19 -0700 (PDT) Received: from smtp.gmail.com (104-218-69-129.dynamic.lnk.ne.allofiber.net. [104.218.69.129]) by smtp.gmail.com with ESMTPSA id c8-20020a023308000000b00482b2095bb6sm1255911jae.127.2024.04.12.13.02.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 13:02:19 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][J/F][PATCH 1/1] wifi: mac80211: fix potential key use-after-free Date: Fri, 12 Apr 2024 15:02:17 -0500 Message-Id: <20240412200217.23419-2-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412200217.23419-1-bethany.jamison@canonical.com> References: <20240412200217.23419-1-bethany.jamison@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Johannes Berg When ieee80211_key_link() is called by ieee80211_gtk_rekey_add() but returns 0 due to KRACK protection (identical key reinstall), ieee80211_gtk_rekey_add() will still return a pointer into the key, in a potential use-after-free. This normally doesn't happen since it's only called by iwlwifi in case of WoWLAN rekey offload which has its own KRACK protection, but still better to fix, do that by returning an error code and converting that to success on the cfg80211 boundary only, leaving the error for bad callers of ieee80211_gtk_rekey_add(). Reported-by: Dan Carpenter Fixes: fdf7cb4185b6 ("mac80211: accept key reinstall without changing anything") Signed-off-by: Johannes Berg (backported from commit 31db78a4923ef5e2008f2eed321811ca79e7f71b) [bjamison: context conflict - added KRACK protection as written in the fix commit since the context conflict was with a neighboring line that doesn't affect the fix commit] CVE-2023-52530 Signed-off-by: Bethany Jamison --- net/mac80211/cfg.c | 3 +++ net/mac80211/key.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 02bd90a537058..0e383beaf723f 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -511,6 +511,9 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, sta->cipher_scheme = cs; err = ieee80211_key_link(key, sdata, sta); + /* KRACK protection, shouldn't happen but just silently accept key */ + if (err == -EALREADY) + err = 0; out_unlock: mutex_unlock(&local->sta_mtx); diff --git a/net/mac80211/key.c b/net/mac80211/key.c index f695fc80088bc..7b427e39831bd 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c @@ -843,7 +843,7 @@ int ieee80211_key_link(struct ieee80211_key *key, */ if (ieee80211_key_identical(sdata, old_key, key)) { ieee80211_key_free_unused(key); - ret = 0; + ret = -EALREADY; goto out; }