From patchwork Sat Dec 16 12:29:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 1876887 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=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-cifs+bounces-493-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SslmN3wHMz20LT for ; Sat, 16 Dec 2023 23:30:28 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3CFA61C217AC for ; Sat, 16 Dec 2023 12:30:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3B272DB71; Sat, 16 Dec 2023 12:30:11 +0000 (UTC) X-Original-To: linux-cifs@vger.kernel.org Received: from mail-il1-f177.google.com (mail-il1-f177.google.com [209.85.166.177]) (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 61B662D797 for ; Sat, 16 Dec 2023 12:30:10 +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-il1-f177.google.com with SMTP id e9e14a558f8ab-35d718382b7so6980865ab.1 for ; Sat, 16 Dec 2023 04:30:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702729809; x=1703334609; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tt85lrQC7Yj4igYLC/WbHrjIg/MuHhtJDM2PYE4oEFI=; b=mTrIY90izW++u6bWpPruYCafvO660NHDDq3rnbvwj2ezCnbkzPFMOi+pKjpFl9Z2a/ P/SxErKVXx3XSe4uQpK891sVCIFHLDRkiLvwooZBa6Am8kpK4aeYm54foZc0RZipkunZ 6MChJbHEYfwH40+Wmns1sDc8BUE8npNxE5zgRn5iSa0Er95iv6OmJvpoQAwNpfcx0mpz WQDYdaqTlp4q8KEA17pyU0PMv5WYwi5TZSr3+vfGUN4cWCu5FceLbrB37zjNQwxpx+gC qBMg4YC4OOBBJItVQnSJlDZ3/OhlAaNr+bfo4oKrw8k3ZrtYMGj8ddsL0P4v5yHVq4Qc W8CQ== X-Gm-Message-State: AOJu0YytHILSO4fJtRnda7MnKNnu7n3erMHE3Cw85XYtcH7CbaUoG4Zs /0jsK+N6ga/wlYv6uMmV2nANCrrdPNY= X-Google-Smtp-Source: AGHT+IFbVdZAauKSUsOgRSpZXLNELweVd1ek/W4+jFivp8Us99cljgzsNoWRBmL2cNV1SKxFBiCx0g== X-Received: by 2002:a05:6e02:1cae:b0:35d:2f2e:f17 with SMTP id x14-20020a056e021cae00b0035d2f2e0f17mr20393498ill.1.1702729808960; Sat, 16 Dec 2023 04:30:08 -0800 (PST) Received: from localhost.localdomain ([110.14.71.32]) by smtp.gmail.com with ESMTPSA id d6-20020a170903230600b001d347a98e7asm6887843plh.260.2023.12.16.04.30.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 04:30:08 -0800 (PST) From: Namjae Jeon To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, senozhatsky@chromium.org, tom@talpey.com, atteh.mailbox@gmail.com, Namjae Jeon Subject: [PATCH 1/3] ksmbd: set v2 lease version on lease upgrade Date: Sat, 16 Dec 2023 21:29:36 +0900 Message-Id: <20231216122938.4511-1-linkinjeon@kernel.org> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If file opened with v2 lease is upgraded with v1 lease, smb server should response v2 lease create context to client. This patch fix smb2.lease.v2_epoch2 test failure. Signed-off-by: Namjae Jeon Acked-by: Tom Talpey --- fs/smb/server/oplock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/smb/server/oplock.c b/fs/smb/server/oplock.c index 562b180459a1..9a19d8b06c8c 100644 --- a/fs/smb/server/oplock.c +++ b/fs/smb/server/oplock.c @@ -1036,6 +1036,7 @@ static void copy_lease(struct oplock_info *op1, struct oplock_info *op2) lease2->duration = lease1->duration; lease2->flags = lease1->flags; lease2->epoch = lease1->epoch++; + lease2->version = lease1->version; } static int add_lease_global_list(struct oplock_info *opinfo) From patchwork Sat Dec 16 12:29:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 1876888 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=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-cifs+bounces-494-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sslmc56Tpz20LT for ; Sat, 16 Dec 2023 23:30:40 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A35081C21730 for ; Sat, 16 Dec 2023 12:30:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6DD92C6B5; Sat, 16 Dec 2023 12:30:14 +0000 (UTC) X-Original-To: linux-cifs@vger.kernel.org Received: from mail-il1-f171.google.com (mail-il1-f171.google.com [209.85.166.171]) (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 6A82D15EA6 for ; Sat, 16 Dec 2023 12:30:13 +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-il1-f171.google.com with SMTP id e9e14a558f8ab-35d77fb7d94so7473025ab.0 for ; Sat, 16 Dec 2023 04:30:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702729812; x=1703334612; 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=94ZYoySqk1WSJl1E6lTo6AJmLWXCNzB6iHYBc9rOWRo=; b=NMcJB1EcWgecYuCa0e5bTFbvgu6pLtcSUcHmlhySTrpEvCc0MnR58oCaPaNymKweRW EkHLXEPF/1fdDL6McYaHbIos1pW8w78vVD+XrgxaBKev1CnTiwOwwappGw2+vfnGQCFv +76C59z/gNMGNm7NH6ar6gmyn5MmedUi2tLdCINy3IOJOdKePesTgm04uhKj85EYTZVD vkWmvqB1DxlwW/aBCNtSmyg0fp7kFGlGdJftynCxOgs2iDESyofzP868cu1Lk6Y9DboB Bs+gxN+fhKh2aklZvUNAqBNUuyDZPC9zr1N+5ilAcuUsqBady59K/H9kLVkgA6H6CaXX ss3g== X-Gm-Message-State: AOJu0YxGQGvVWDUoK6uTrY0hkyk0luI6FaO7nvJ4DGk1lGJsH1YWatqJ Y8ZZabDbfdkeDuwu2xyDoWEEDSSAo8o= X-Google-Smtp-Source: AGHT+IE3Dbx3eqtKrFuFM079/dZD1G+yU5kpl068IunbNOEkdPpUAnw1fYazIcC1XxW4YGXR44i9RQ== X-Received: by 2002:a05:6e02:1808:b0:35f:a560:2f01 with SMTP id a8-20020a056e02180800b0035fa5602f01mr519569ilv.62.1702729812098; Sat, 16 Dec 2023 04:30:12 -0800 (PST) Received: from localhost.localdomain ([110.14.71.32]) by smtp.gmail.com with ESMTPSA id d6-20020a170903230600b001d347a98e7asm6887843plh.260.2023.12.16.04.30.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 04:30:11 -0800 (PST) From: Namjae Jeon To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, senozhatsky@chromium.org, tom@talpey.com, atteh.mailbox@gmail.com, Namjae Jeon Subject: [PATCH 2/3] ksmbd: fix potential circular locking issue in smb2_set_ea() Date: Sat, 16 Dec 2023 21:29:37 +0900 Message-Id: <20231216122938.4511-2-linkinjeon@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231216122938.4511-1-linkinjeon@kernel.org> References: <20231216122938.4511-1-linkinjeon@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 smb2_set_ea() can be called in parent inode lock range. So add get_write argument to smb2_set_ea() not to call nested mnt_want_write(). Signed-off-by: Namjae Jeon --- fs/smb/server/smb2pdu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 652ab429bf2e..a2f729675183 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -2311,11 +2311,12 @@ static noinline int create_smb2_pipe(struct ksmbd_work *work) * @eabuf: set info command buffer * @buf_len: set info command buffer length * @path: dentry path for get ea + * @get_write: get write access to a mount * * Return: 0 on success, otherwise error */ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len, - const struct path *path) + const struct path *path, bool get_write) { struct mnt_idmap *idmap = mnt_idmap(path->mnt); char *attr_name = NULL, *value; @@ -3003,7 +3004,7 @@ int smb2_open(struct ksmbd_work *work) rc = smb2_set_ea(&ea_buf->ea, le32_to_cpu(ea_buf->ccontext.DataLength), - &path); + &path, false); if (rc == -EOPNOTSUPP) rc = 0; else if (rc) @@ -5992,7 +5993,7 @@ static int smb2_set_info_file(struct ksmbd_work *work, struct ksmbd_file *fp, return -EINVAL; return smb2_set_ea((struct smb2_ea_info *)req->Buffer, - buf_len, &fp->filp->f_path); + buf_len, &fp->filp->f_path, true); } case FILE_POSITION_INFORMATION: { From patchwork Sat Dec 16 12:29:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 1876890 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=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-cifs+bounces-495-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sslmq2qgNz20LT for ; Sat, 16 Dec 2023 23:30:51 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6016C1C2174E for ; Sat, 16 Dec 2023 12:30:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 844F82E623; Sat, 16 Dec 2023 12:30:17 +0000 (UTC) X-Original-To: linux-cifs@vger.kernel.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 3AD0C15EA6 for ; Sat, 16 Dec 2023 12:30:16 +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-pg1-f174.google.com with SMTP id 41be03b00d2f7-5c21e185df5so1320832a12.1 for ; Sat, 16 Dec 2023 04:30:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702729815; x=1703334615; 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=eKxsGNdycCsapBkqubfGw/Dn5fK6LpSzNNn2n4GD9mA=; b=WQK+WogbSMjm3yLr6kmzRYDtFrqq8Uss7pruHJIbom/oKT5pN+e+pwbI+W+bbvSoHs ncXEzWL2Cw9TAgmNCQuWGod8QNGOUWhq3mJPttSOTz+CCKOHijLRvUINYAmC8J/z5KPo uoWaRQmCUS63bpN3ImGfQ/2ETgZYLsVfoRrV8gR5OUWnIpQMD3rEERaUxb0UX27qrENT bPGmd1lUgQCIpjDx6aGJPQJJlhdG1vTrI66JGktHFwTNWgBxF9b5Ec6a52s3CMYHKaBV RBQQ0a+hPBv+e21k4FbPoY7GI9hGx8c20NR78GeoQo5gQxst+YTl1SDml3C30tqVkGrf Hwtg== X-Gm-Message-State: AOJu0YxqZcXTHvgocjAcEAsQ7XX15BqoQM5EjWPVWIYMCjTr4yMmcxj5 JuI504tA/9YCBc99LG+/57fRoKTuqgA= X-Google-Smtp-Source: AGHT+IEoq40OA7Ggc/aMBxVAHrFvTQ3lm8rz/4xdxqUFcPWwtAWrkxzqvDeKPuOVS+/QkuAdSmE1cw== X-Received: by 2002:a17:903:41c9:b0:1d3:7a3b:d391 with SMTP id u9-20020a17090341c900b001d37a3bd391mr4081363ple.9.1702729814996; Sat, 16 Dec 2023 04:30:14 -0800 (PST) Received: from localhost.localdomain ([110.14.71.32]) by smtp.gmail.com with ESMTPSA id d6-20020a170903230600b001d347a98e7asm6887843plh.260.2023.12.16.04.30.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 04:30:14 -0800 (PST) From: Namjae Jeon To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, senozhatsky@chromium.org, tom@talpey.com, atteh.mailbox@gmail.com, Namjae Jeon Subject: [PATCH 3/3] ksmbd: don't increment epoch if current state and request state are same Date: Sat, 16 Dec 2023 21:29:38 +0900 Message-Id: <20231216122938.4511-3-linkinjeon@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231216122938.4511-1-linkinjeon@kernel.org> References: <20231216122938.4511-1-linkinjeon@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If existing lease state and request state are same, don't increment epoch in create context. Signed-off-by: Namjae Jeon --- fs/smb/server/oplock.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/smb/server/oplock.c b/fs/smb/server/oplock.c index 9a19d8b06c8c..77f20d34ed9a 100644 --- a/fs/smb/server/oplock.c +++ b/fs/smb/server/oplock.c @@ -105,7 +105,7 @@ static int alloc_lease(struct oplock_info *opinfo, struct lease_ctx_info *lctx) lease->is_dir = lctx->is_dir; memcpy(lease->parent_lease_key, lctx->parent_lease_key, SMB2_LEASE_KEY_SIZE); lease->version = lctx->version; - lease->epoch = le16_to_cpu(lctx->epoch); + lease->epoch = le16_to_cpu(lctx->epoch) + 1; INIT_LIST_HEAD(&opinfo->lease_entry); opinfo->o_lease = lease; @@ -541,6 +541,9 @@ static struct oplock_info *same_client_has_lease(struct ksmbd_inode *ci, continue; } + if (lctx->req_state != lease->state) + lease->epoch++; + /* upgrading lease */ if ((atomic_read(&ci->op_count) + atomic_read(&ci->sop_count)) == 1) { @@ -1035,7 +1038,7 @@ static void copy_lease(struct oplock_info *op1, struct oplock_info *op2) SMB2_LEASE_KEY_SIZE); lease2->duration = lease1->duration; lease2->flags = lease1->flags; - lease2->epoch = lease1->epoch++; + lease2->epoch = lease1->epoch; lease2->version = lease1->version; } @@ -1448,7 +1451,7 @@ void create_lease_buf(u8 *rbuf, struct lease *lease) memcpy(buf->lcontext.LeaseKey, lease->lease_key, SMB2_LEASE_KEY_SIZE); buf->lcontext.LeaseFlags = lease->flags; - buf->lcontext.Epoch = cpu_to_le16(++lease->epoch); + buf->lcontext.Epoch = cpu_to_le16(lease->epoch); buf->lcontext.LeaseState = lease->state; memcpy(buf->lcontext.ParentLeaseKey, lease->parent_lease_key, SMB2_LEASE_KEY_SIZE);