From nobody Tue Oct 7 21:36:27 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (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 524F42E371A; Sat, 5 Jul 2025 02:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751683889; cv=none; b=umINmwnyYx2C6iEUROPhCgjUUxd3OtK4GkF8wbOLRWSOEYZ5G6x9YcP2v4FJJFqbiMpRG6q84Hn5xEuUMLKzlstQDPZSSa2cCNpUxKUyrgIJqUl5NRUm/K5PmkHMPc9caNu8F8UV0Kzkqr5Uqr54updM/a5/XEWhVDGH3ThFVaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751683889; c=relaxed/simple; bh=6NyZv8lozIrsP7Itz3qOaPMzVZsGuwwnQvzBvSweyyM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=uhgJfowbOSQ+zeuw3mfSqDwhs0yXr/O/QGI6Dt+AQllWLrRUav2Y3L0JQJvZnsfhIKq4DJlu6FCfUBI43bqksTg81gphk/brxCkppINR315IWVs7WZcADjqveoLTst7gv5wJP8XH4Vqaatpy4YokHAyhqQwwZzxZt9K5lJ2NEWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4bYw4W68X6zYQtM8; Sat, 5 Jul 2025 10:51:23 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id B071D1A0C6A; Sat, 5 Jul 2025 10:51:22 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.170]) by APP3 (Coremail) with SMTP id _Ch0CgBHpyQmk2hoam_DAg--.41567S4; Sat, 05 Jul 2025 10:51:20 +0800 (CST) From: Wang Zhaolong To: sfrench@samba.org, ematsumiya@suse.de Cc: linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org, wangzhaolong1@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com, chengzhihao1@huawei.com Subject: [PATCH] smb: client: fix use-after-free in crypt_message when using async crypto Date: Sat, 5 Jul 2025 10:51:18 +0800 Message-Id: <20250705025118.48080-1-wangzhaolong@huaweicloud.com> X-Mailer: git-send-email 2.34.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _Ch0CgBHpyQmk2hoam_DAg--.41567S4 X-Coremail-Antispam: 1UD129KBjvJXoWxWw1fCFW7Xry3Xr13AFW7XFb_yoW5uryfpF WFyFWFyrWrJrn2g395JrWrAa4FvrZ3uw13GFZ7Gw17CFyrZr1vvry2k3WjqFy5AFWkJ34U Wr4vvwn0qF12yFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyEb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6r1S6rWUM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r1q6r43MxAIw28IcxkI 7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxV Cjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY 6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6x AIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY 1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU17KsUUUUUU== X-CM-SenderInfo: pzdqw6xkdrz0tqj6x35dzhxuhorxvhhfrp/ Content-Type: text/plain; charset="utf-8" The CVE-2024-50047 fix removed asynchronous crypto handling from crypt_message(), assuming all crypto operations are synchronous. However, when hardware crypto accelerators are used, this can cause use-after-free crashes: crypt_message() // Allocate the creq buffer containing the req creq =3D smb2_get_aead_req(..., &req); // Async encryption returns -EINPROGRESS immediately rc =3D enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); // Free creq while async operation is still in progress kvfree_sensitive(creq, ...); Hardware crypto modules often implement async AEAD operations for performance. When crypto_aead_encrypt/decrypt() returns -EINPROGRESS, the operation completes asynchronously. Without crypto_wait_req(), the function immediately frees the request buffer, leading to crashes when the driver later accesses the freed memory. This results in a use-after-free condition when the hardware crypto driver later accesses the freed request structure, leading to kernel crashes with NULL pointer dereferences. The issue occurs because crypto_alloc_aead() with mask=3D0 doesn't guarantee synchronous operation. Even without CRYPTO_ALG_ASYNC in the mask, async implementations can be selected. Fix by restoring the async crypto handling: - DECLARE_CRYPTO_WAIT(wait) for completion tracking - aead_request_set_callback() for async completion notification - crypto_wait_req() to wait for operation completion This ensures the request buffer isn't freed until the crypto operation completes, whether synchronous or asynchronous, while preserving the CVE-2024-50047 fix. Fixes: b0abcd65ec54 ("smb: client: fix UAF in async decryption") Link: https://lore.kernel.org/all/8b784a13-87b0-4131-9ff9-7a8993538749@huaw= eicloud.com/ Cc: stable@vger.kernel.org Signed-off-by: Wang Zhaolong Reviewed-by: Paulo Alcantara (Red Hat) --- fs/smb/client/smb2ops.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 1468c16ea9b8..cb659256d219 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -4314,10 +4314,11 @@ crypt_message(struct TCP_Server_Info *server, int n= um_rqst, struct scatterlist *sg; u8 sign[SMB2_SIGNATURE_SIZE] =3D {}; u8 key[SMB3_ENC_DEC_KEY_SIZE]; struct aead_request *req; u8 *iv; + DECLARE_CRYPTO_WAIT(wait); unsigned int crypt_len =3D le32_to_cpu(tr_hdr->OriginalMessageSize); void *creq; size_t sensitive_size; =20 rc =3D smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key); @@ -4364,11 +4365,15 @@ crypt_message(struct TCP_Server_Info *server, int n= um_rqst, =20 aead_request_set_tfm(req, tfm); aead_request_set_crypt(req, sg, sg, crypt_len, iv); aead_request_set_ad(req, assoc_data_len); =20 - rc =3D enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req); + aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, + crypto_req_done, &wait); + + rc =3D crypto_wait_req(enc ? crypto_aead_encrypt(req) + : crypto_aead_decrypt(req), &wait); =20 if (!rc && enc) memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE); =20 kvfree_sensitive(creq, sensitive_size); --=20 2.34.3