Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 3236917C3 for ; Sun, 31 Dec 2023 07:16:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1d4ab4e65aeso3238785ad.0 for ; Sat, 30 Dec 2023 23:16:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704006987; x=1704611787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vk4KEYTS5PbAcN3zlGPTNGiJcZTRImVfIOjC4qzaAJs=; b=LD+TZlWTWULsmKRPjeawGWHbpbYaRWnJE6/8Vdzw6XLZqU2AWunMVW0mLNLvhxXcOa tuW7TNquBNo3J1gORUVk2imOeTF8h/SkA3zd0JcgLi5zRSaS8LoWte5RVBKNKGUwD8lc 7qN52xMSVFzZMwgHwX58oI5QvNZip/ecX898TuU4PVxFTNDadwviBvUZt9c96/Y1bHZP CEZQ3SyW8hWTegyw+zaKhfJ4eUQoWucsOsBP6HLKCukucASKguAIezwi2+9S5u0UqlZS Kao11JR5ARswH1LTrEzSWmHAyYRtULyxSkausjCTSdkF/4nsXTcjoyNIcr8DoGVMvtCi /PcA== X-Gm-Message-State: AOJu0Yxud6MUcuWyRubjbzt/SoUgXOznCQV+f3nDrX/EXLKlIncMUHKw pAZhE5uMXn3hZtRPYR3SPEM= X-Google-Smtp-Source: AGHT+IETRSyj5EOPvKVZanJyKDgKJ7A4MOuHycv1lIYPEgAqcepFMMB3GYdiIXtN6J/UjdPR5rzAig== X-Received: by 2002:a17:90a:d58f:b0:28b:d560:d44a with SMTP id v15-20020a17090ad58f00b0028bd560d44amr17018738pju.44.1704006987626; Sat, 30 Dec 2023 23:16:27 -0800 (PST) Received: from localhost.localdomain ([110.14.71.32]) by smtp.gmail.com with ESMTPSA id a2-20020a63d402000000b005c661a432d7sm17146357pgh.75.2023.12.30.23.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Dec 2023 23:16:27 -0800 (PST) From: Namjae Jeon To: gregkh@linuxfoundation.org, stable@vger.kernel.org, sashal@kernel.org Cc: smfrench@gmail.com, Namjae Jeon , luosili , Steve French Subject: [PATCH 6.1.y 47/73] ksmbd: fix race condition from parallel smb2 lock requests Date: Sun, 31 Dec 2023 16:13:06 +0900 Message-Id: <20231231071332.31724-48-linkinjeon@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231231071332.31724-1-linkinjeon@kernel.org> References: <20231231071332.31724-1-linkinjeon@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit [ Upstream commit 75ac9a3dd65f7eab4d12b0a0f744234b5300a491 ] There is a race condition issue between parallel smb2 lock request. Time + Thread A | Thread A smb2_lock | smb2_lock | insert smb_lock to lock_list | spin_unlock(&work->conn->llist_lock) | | | spin_lock(&conn->llist_lock); | kfree(cmp_lock); | // UAF! | list_add(&smb_lock->llist, &rollback_list) + This patch swaps the line for adding the smb lock to the rollback list and adding the lock list of connection to fix the race issue. Reported-by: luosili Signed-off-by: Namjae Jeon Signed-off-by: Steve French --- fs/smb/server/smb2pdu.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 805b51b815bd..a8d3f1daefb5 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -7038,10 +7038,6 @@ int smb2_lock(struct ksmbd_work *work) ksmbd_debug(SMB, "would have to wait for getting lock\n"); - spin_lock(&work->conn->llist_lock); - list_add_tail(&smb_lock->clist, - &work->conn->lock_list); - spin_unlock(&work->conn->llist_lock); list_add(&smb_lock->llist, &rollback_list); argv = kmalloc(sizeof(void *), GFP_KERNEL); @@ -7073,9 +7069,6 @@ int smb2_lock(struct ksmbd_work *work) if (work->state != KSMBD_WORK_ACTIVE) { list_del(&smb_lock->llist); - spin_lock(&work->conn->llist_lock); - list_del(&smb_lock->clist); - spin_unlock(&work->conn->llist_lock); locks_free_lock(flock); if (work->state == KSMBD_WORK_CANCELLED) { @@ -7095,19 +7088,16 @@ int smb2_lock(struct ksmbd_work *work) } list_del(&smb_lock->llist); - spin_lock(&work->conn->llist_lock); - list_del(&smb_lock->clist); - spin_unlock(&work->conn->llist_lock); release_async_work(work); goto retry; } else if (!rc) { + list_add(&smb_lock->llist, &rollback_list); spin_lock(&work->conn->llist_lock); list_add_tail(&smb_lock->clist, &work->conn->lock_list); list_add_tail(&smb_lock->flist, &fp->lock_list); spin_unlock(&work->conn->llist_lock); - list_add(&smb_lock->llist, &rollback_list); ksmbd_debug(SMB, "successful in taking lock\n"); } else { goto out; -- 2.25.1