From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (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 126964EA363 for ; Tue, 19 May 2026 14:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779201875; cv=none; b=n8tnPPb6Zd8mbbHKShPCVFG4+DMQ0dluGqiOpP4bMLZpKnE+F5KsEDZ7fFMTHjFZcideiyv79lxEatCNvMpFlrk7UcnUB6bCPAw3q4gq7pXgjG0Sl255xAE3c84EacmMBlJZ7MPt1ryJJSbT8QRZqGshsCxdyxTWqHDrgfYh22U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779201875; c=relaxed/simple; bh=mwiEUl6i8qzKyhgvrXCmm8xKF60p0orj3WXB0AZY4AQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XR/rtaAkY7+d48KJbJhb4U3ivfedHiGXmimj7/+o4L2WaIl7FrSC5d5IJW0vW35VAn9R9QZoEIdxJTXSfRrZdeMW8r81xZXtX5lc8Gj6C3G26WYvJRwcu/56DN5IrfOdh7Jmbz0cWbRgAg8htyyvluHUazkVmh5MxiSXXXHRCIY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=s3spdfcX; arc=none smtp.client-ip=74.125.82.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s3spdfcX" Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-132d1b2519eso9306732c88.0 for ; Tue, 19 May 2026 07:44:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779201861; x=1779806661; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Seai4fWqb4mwDhLXDN1f51FodXQt4GGEE1K9qVn4MNo=; b=s3spdfcXlGF5UYUVsQgY6pxGGTc0bC+D+uuP2ZPM/qi39+sQcCmC7qd2m8D+fqyVEv LmqEh5jfhQbsO4Ysv5cUmsZam/+e4qG1k+yeCc/PjiyY2Ruegm/R7x+M5DXuqv+ioXlf hgX9He+tq2yv7Q/K2lgrA1HDCvb8kN2F+U1ZPZGPhu16e9cNhKp2z6Bref0i724LBxk3 1EwOEjMEwRC/Tl0fYByXSVNeh/l3HkR5pfS9V1NseozJksO0kVWmJxBOr0/Dd9GPof4N HBpeH4oxuG725Zbyq2t3LxKSlwrXSrUE4u4+eE2fCW3nNJ/sfCQBdB6zJK0VmCb0V989 RtLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779201861; x=1779806661; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Seai4fWqb4mwDhLXDN1f51FodXQt4GGEE1K9qVn4MNo=; b=GYrpGwzpGZBnmgBysmjvrwoK9KmsjTxdlZtteJsUm086fl2Zo6A81b1IsIaeaB4Nvd X/glpHXKZZQprz+Vf3Va9MZFBFDMBCJ6RNcaP+TfmMWL00/MxHjwY48Vg6VZ+HHCijVB +owUouCj3vp8YA8hftmLaG5S9Q9WtxXzaXJvmKG84CSuMK5AJdvJreoc0VrIxq1ucfCO q3pFpKAZoALLGoA8+wvD83sHj1CWjz2buyJFlOvRbq5TNL++piDwrYj/Q6dl6VYA9cPv Vi9LkNsMwzh1sWAnrMD1M2Cb+BURaRFGKE5shjvR4jwlbZGa85aCGIrBZiGil6932/NU 6JbQ== X-Forwarded-Encrypted: i=1; AFNElJ9ESncLIaqRyFtu/23MebF746JmaBlQEn2wLeu80cW7mhQQjRS7YLyOHpscbFAULLv1B+X7CaTiknpdXGw=@vger.kernel.org X-Gm-Message-State: AOJu0YzGg7yGsv06fVRqzwvSE1W64hV5G8E+HqdtGofnPGXHIW1apVoS H6kfXp+B828qhS0EkpHTc3TDaf8er48SflVwfoIAgrA2/nnQixO89e4v X-Gm-Gg: Acq92OGmjFwY8/3g3WPxvrEcFuhZ4Kwu76BDIGCqrGs40yFu7alCjf7PsZjMmyp/M/t Z4DkoQ3OyduH9AnUVnBRYKqYb5jVd3yqCpubILmnca689qR3rx9VWOPRbDj1MzFoNyuY7dl0tTR bV3lUYE2ayRGVueIRG8v+d5mJ1vlGPMJyq0JNZaxYf5E6SJCuFbFylm5I8JREYZ+wDyQNQEtgv+ CjO1Kya8s70Cfd+RtzHXtYDzbw4gETUlei/xZPkid/mbteFWDgGGABLJ2d6VyyJSoFQnXp/f63m OSO+9lpELCmICWqZGAtRC44B9kdWDCSHDmD6hBGv6w5qMzRiIdlUYTZNdNzPns7MGyUpW63ADu2 Tlys7ZuMeTvXGfc+6cvigAfg0WN2BW7DN9fZqod7YW1C1CPdUO1KS0DZ/H7zsPFMOAMPlOCtiwV FmfQUpIjxHb1N7uY2AWs82VgaWMCEi1z7FeG9ZerA6EI+S1NVr X-Received: by 2002:a05:7022:7a2:b0:132:2486:acb with SMTP id a92af1059eb24-13504415962mr8368979c88.12.1779201860844; Tue, 19 May 2026 07:44:20 -0700 (PDT) Received: from localhost.localdomain ([148.135.103.3]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-135e5c0a918sm1276868c88.14.2026.05.19.07.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 07:44:20 -0700 (PDT) From: Shaomin Chen To: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Cc: David Howells , Jarkko Sakkinen , Paul Moore , James Morris , "Serge E. Hallyn" Subject: [bug report] keys: request_key_auth payload use-after-free in keyctl_instantiate_key_common() Date: Tue, 19 May 2026 22:44:03 +0800 Message-ID: <20260519144403.436694-1-eeesssooo020@gmail.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi, keyctl_instantiate_key_common() can use a stale request_key_auth payload after the current request-key authorisation key has been revoked. The relevant code pattern is: rka = instkey->payload.data[0]; ... copy_from_iter_full(payload, plen, from); /* can fault and sleep */ ... get_instantiation_keyring(ringid, rka, &dest_keyring); key_instantiate_and_link(rka->target_key, payload, plen, dest_keyring, instkey); keyctl_instantiate_key_common() does not hold authkey->sem, an RCU read-side critical section, or a reference to the request_key_auth payload across the sleeping copy and later rka dereferences. One race sequence is: Task A: request-key helper child Task B: original request_key path ------------------------------- --------------------------------- assume request-key authority enter KEYCTL_INSTANTIATE_IOV rka = instkey->payload.data[0] block in copy_from_iter_full() helper parent instantiates target key helper returns to kernel complete_request_key(authkey, 0) key_revoke(authkey) request_key_auth_revoke(authkey) rcu_assign_keypointer(authkey, NULL) call_rcu(&rka->rcu, ...) request_key_auth_rcu_disposal() free_request_key_auth(rka) resume from copy_from_iter_full() get_instantiation_keyring(..., rka, ...) key_instantiate_and_link(rka->target_key, ...) I reproduced this on a current upstream v7.1-rc3 based tree, HEAD ab5fce87a778c, with KASAN enabled: BUG: KASAN: slab-use-after-free in keyctl_instantiate_key_common+0x1dc/0x2a0 Read of size 8 Allocated by task: request_key_auth_new+0xe0/0x4d0 Freed by task: key_revoke+0x62/0xc0 call_sbin_request_key+0x6cb/0x740 The reproducer uses a request-key helper that forks a second process with the request-key authority. The second process enters KEYCTL_INSTANTIATE_IOV and blocks in copy_from_iter_full() on a user fault after rka has been loaded. The original helper then instantiates the target key and returns, which revokes the auth key and queues the request_key_auth payload for RCU freeing. When the blocked instantiate path resumes, it dereferences the stale rka pointer. I can provide the reproducer and a candidate patch. Regards, Shaomin Chen