From patchwork Wed Jun 26 21:39:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1952794 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 4W8ZqL244Dz20bH 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 1sMaMp-0004pF-7Q; Wed, 26 Jun 2024 21:39:51 +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 1sMaMn-0004of-4L for kernel-team@lists.ubuntu.com; Wed, 26 Jun 2024 21:39:49 +0000 Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) (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 0C3113F5EF for ; Wed, 26 Jun 2024 21:39:49 +0000 (UTC) Received: by mail-ot1-f70.google.com with SMTP id 46e09a7af769-700cd2139cfso2741896a34.3 for ; Wed, 26 Jun 2024 14:39:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719437987; x=1720042787; 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=TBgyvOTcDhjOGGpQpZSGeuuuQYV2MCdw/5+r5SKeJKQ=; b=PJSsMMJr5fDmEGXHEp5BeY/Sbxi+udbNdAzYkacTR2XaFkJBAO70muluO/sJzu0Oya hwaL70ODws9yjbd5sgVh2MNgb6ittyiWRiaPS3kw3DnADpmMoBXfWDXRD8B16EqSohIk 59uPjZ9LXeArQqIZiwEKlLi+Q0YM3hWKG65bCthKM5cDYz4A8HEA1flfgBh29vCwEBI1 hC5RTma+tVzaYoOCXd539zxh7oounMZThPGewQAGuzuk7hU15z6FKtaul97zZn/sKqLN SGwI6Fkvh+DAerwvdiUIx58PtU8yw3upfSLpOcwiKVL1GJFEqNizHGxf+Izl0mWi5MCg 1DyA== X-Gm-Message-State: AOJu0YztSkx5002HkpEJ87CzjOW7PnY5eyHphsme4Z7+HKCkvLbBnAMc It/WPhzzhMc6kdYqiUhf8gxn5PYMCo8YdWTwJtYqrt6wScqDNi2abQTkyQ2ogw/OijLvXMGq9/N HS5chUVfMtEHhQ5rL0yVfPFrVccD3FmAzvzqu/Qcu7Tleenm1eiWsK2Vo6N7p1PDPGpq1HHKUcj 2uuyPDjwpTUg== X-Received: by 2002:a9d:684a:0:b0:700:cb08:1025 with SMTP id 46e09a7af769-700cb081576mr6562057a34.8.1719437986691; Wed, 26 Jun 2024 14:39:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvZrdZ9Pny4AlEm0J5IB5N3eUsOAdQtFrtboc6tBza2+3FhGBelWGRe1fpMd9S2AuShLxiVA== X-Received: by 2002:a9d:684a:0:b0:700:cb08:1025 with SMTP id 46e09a7af769-700cb081576mr6562042a34.8.1719437986314; Wed, 26 Jun 2024 14:39:46 -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.45 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: [Jammy][PATCH 1/1] smb: client: fix use-after-free bug in cifs_debug_data_proc_show() Date: Wed, 26 Jun 2024 17:39:42 -0400 Message-Id: <20240626213942.156622-3-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: substitute the if statement with (ses->status == CifsExiting) since backporting dd3cd8709ed5 (“cifs: use new enum for ses_status”) is too hard. Also replace ses->ses_lock with GlobalMid_Lock as well for same reason for d7d7a66aacd6 (“cifs: avoid use of global locks for high contention data”). ] 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 e7501533c2ec9..efd4affd8218a 100644 --- a/fs/cifs/cifs_debug.c +++ b/fs/cifs/cifs_debug.c @@ -380,6 +380,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; + } i++; if ((ses->serverDomain == NULL) || (ses->serverOS == NULL) || @@ -400,6 +405,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); seq_printf(m, "\n\tSecurity type: %s ", get_security_type_str(server->ops->select_sectype(server, ses->sectype)));