From patchwork Wed Jun 26 21:39:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1952792 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 4W8ZqL030pz20X6 for ; Thu, 27 Jun 2024 07:39:57 +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 1sMaMn-0004ob-28; Wed, 26 Jun 2024 21:39:49 +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 1sMaMl-0004oK-TK for kernel-team@lists.ubuntu.com; Wed, 26 Jun 2024 21:39:47 +0000 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (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 B8DBB3F5B0 for ; Wed, 26 Jun 2024 21:39:47 +0000 (UTC) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-79d5ae48999so47891285a.1 for ; Wed, 26 Jun 2024 14:39:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719437986; x=1720042786; 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=5OQU1ZkKXSzqlQvcrWnFmDLiWPvmO5wvArif0jSAWKU=; b=UoRe/1Zyabz1C+DKSG3i+eswesAzvsmTSHB2VWml984smC7YxW5gO2L1OwuUA+mtDg u1K1+hudlQXzRUBnJv0Ilnkii8+h3YpMklOWEdBjP06mqgPg0atWWXTeAdTkodcqR6cv NBdmrR04OswJM+V3cHLqNqz/c7TY4V5fv58yC4PE0VanlJItULoyXs68GNUOxRh4cZ0U WnVOHngg+A3NKOayQ1NVB0Ce8jpwSFSsgdym2z/ki3Lbf8vHm1BHD0TuWsM/Crwk66V/ 7xyPf6rZzA8+QYYFJ/5ZjVd9OQ9wUjocwSvieCGmlmiurSIOq/PdOZNgHcKOoQhKMPDt /SKw== X-Gm-Message-State: AOJu0YyZ5IRJWpIYXvlDDjkEx04XryjfQapl/hwPaLNEEFQ1NGCaEaHT RVL5ikF8r09lJzFvwtbOV7g3uWgxsnzgm1r8yqTp7CLSGyKU2fnO0ZZo74hYxdjWwr53H6vFiMN Hqq9pkn+b2hSNUxrBVfTIwxGlsfCBxrnGHLZj4dJT1RRwwq46L6j28UeROSAZhPgPujQwWJyzsK xMFLUHQAx/EA== X-Received: by 2002:a05:620a:4411:b0:795:81a4:6e3b with SMTP id af79cd13be357-79be7036693mr1337019285a.54.1719437985824; Wed, 26 Jun 2024 14:39:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMsZ7S8BTmDropkHSM4CcGSpc+rNB4UHGaWMokNpGvZhmaQTDN/tLj7D2/JCPHCejJmL0p1g== X-Received: by 2002:a05:620a:4411:b0:795:81a4:6e3b with SMTP id af79cd13be357-79be7036693mr1337017785a.54.1719437985479; Wed, 26 Jun 2024 14:39:45 -0700 (PDT) Received: from cache-ubuntu.hsd1.nj.comcast.net ([2001:67c:1562:8007::aac:4795]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bce942910sm532633785a.129.2024.06.26.14.39.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 14:39:45 -0700 (PDT) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [Focal][PATCH 1/1] smb: client: fix use-after-free bug in cifs_debug_data_proc_show() Date: Wed, 26 Jun 2024 17:39:41 -0400 Message-Id: <20240626213942.156622-2-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240626213942.156622-1-yuxuan.luo@canonical.com> References: <20240626213942.156622-1-yuxuan.luo@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: Paulo Alcantara Skip SMB sessions that are being teared down (e.g. @ses->ses_status == SES_EXITING) in cifs_debug_data_proc_show() to avoid use-after-free in @ses. This fixes the following GPF when reading from /proc/fs/cifs/DebugData while mounting and umounting [ 816.251274] general protection fault, probably for non-canonical address 0x6b6b6b6b6b6b6d81: 0000 [#1] PREEMPT SMP NOPTI ... [ 816.260138] Call Trace: [ 816.260329] [ 816.260499] ? die_addr+0x36/0x90 [ 816.260762] ? exc_general_protection+0x1b3/0x410 [ 816.261126] ? asm_exc_general_protection+0x26/0x30 [ 816.261502] ? cifs_debug_tcon+0xbd/0x240 [cifs] [ 816.261878] ? cifs_debug_tcon+0xab/0x240 [cifs] [ 816.262249] cifs_debug_data_proc_show+0x516/0xdb0 [cifs] [ 816.262689] ? seq_read_iter+0x379/0x470 [ 816.262995] seq_read_iter+0x118/0x470 [ 816.263291] proc_reg_read_iter+0x53/0x90 [ 816.263596] ? srso_alias_return_thunk+0x5/0x7f [ 816.263945] vfs_read+0x201/0x350 [ 816.264211] ksys_read+0x75/0x100 [ 816.264472] do_syscall_64+0x3f/0x90 [ 816.264750] entry_SYSCALL_64_after_hwframe+0x6e/0xd8 [ 816.265135] RIP: 0033:0x7fd5e669d381 Cc: stable@vger.kernel.org Signed-off-by: Paulo Alcantara (SUSE) Signed-off-by: Steve French (backported from commit d328c09ee9f15ee5a26431f5aad7c9239fa85e62) [yuxuan.luo: manually applied the patch with context adjustment: `status` substituting `ses_status` and `CifsExiting` for `SES_EXITING`. ] CVE-2023-52752 Signed-off-by: Yuxuan Luo --- fs/cifs/cifs_debug.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c index efb2928ff6c89..f246768e3e8ab 100644 --- a/fs/cifs/cifs_debug.c +++ b/fs/cifs/cifs_debug.c @@ -337,6 +337,11 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v) list_for_each(tmp2, &server->smb_ses_list) { ses = list_entry(tmp2, struct cifs_ses, smb_ses_list); + spin_lock(&GlobalMid_Lock); + if (ses->status == CifsExiting) { + spin_unlock(&GlobalMid_Lock); + continue; + } if ((ses->serverDomain == NULL) || (ses->serverOS == NULL) || (ses->serverNOS == NULL)) { @@ -356,6 +361,7 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v) ses->ses_count, ses->serverOS, ses->serverNOS, ses->capabilities, ses->status); } + spin_unlock(&GlobalMid_Lock); if (server->rdma) seq_printf(m, "RDMA\n\t"); seq_printf(m, "TCP status: %d Instance: %d\n\tLocal Users To "