Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp917101rdb; Fri, 9 Feb 2024 05:17:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVgtTfanliPbgOFRRnZ25OgUj8LGam+ChtU/MsSV/TrJQGojtDwqq2abUP/f1MMyp+MNgWNlpj6mfQnHLHStWwoodm8p1g5U3vCN8wmgQ== X-Google-Smtp-Source: AGHT+IFEVaBVx6GKuW/Cz6a30oPzMPzi99NcMdXl1h1S1CiXE0K+pqyIAijUOpOWbtPC+fSRqV8v X-Received: by 2002:a17:906:856:b0:a38:8d72:250f with SMTP id f22-20020a170906085600b00a388d72250fmr1144608ejd.44.1707484659400; Fri, 09 Feb 2024 05:17:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707484659; cv=pass; d=google.com; s=arc-20160816; b=isIyg1SWq+nLK9kfo6cjwQjGXPBfKQv5LvwB4WpEBpY4zhIlIhsuW7MXhcYVgzcwWu bxmlBT5mB56Z1yqGeneTPxZ/mnvBS4WPaL+MQ/F15VS0CMG6gdYUfTKOclvGfVU+COCo 1S5Z7ksPLwH2C/O3l4eO57/N1IfnL4pTbzkKo/JKRpbStRI/RUm57NvR+6jUbNsqpY2v YgjFj00lqq/oZkv8f4hUawF9NcwEdTRL6hLHQNrnimtaxLhta2lJHvxznooDSIZircqP 9lZxDxunXDYzV7ZVjfZslUuabliDuo0AcGWfYHhKBGyvwlf55wcMcIlfcAMAc4py//VW YdzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=rDApktuVCr/Bgtqf/JWCLMMqtiZv/VT6n1DxWHxTHaM=; fh=fhFeo9Zjr0aRN8AD5R+c82DxJjT8IF4AhvTJfvUhlhM=; b=qqlpQjFDjDo61U06ISxji08g/7hx1Nz6yFHzwYk9t9a2H9gulRz/FeD87f5ZTbc+Lw PmaiGVKnX/DlaHy5qCr+K861o7+6kV6uejVc9qku7gQib9vimQlahgJfQQ/ojXEtNzCE VZc5vsxMag3D2YndGn/1Lo9Dp0vt1q4RQVa99dKm+PaUHvG4o13KxWZOxEChrHmEIfud NSuWINdTQ8Wy54Au/b+AMczHXr2PpFWT8mXX+9Dttk/sMJR05GiKZQDD5gQ2+LU13lha uub74VuzS2aJyAo6L1WqWqsPhxkfskvNPz7VhqsdDA2hVaY0XPiP3jLvUw4TfmMWagzR 5jig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EXcj3iuY; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-59347-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59347-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCULIEI0hrxcxcy4rI/3f9jhjdKOP+ZArAy/4yp2EJcVZq0MmljT7lbUkUFSbTv1Fm3KXfEzYCqftIZFMJhJ69Z7JONEcYe+vRPi6IhvhA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r19-20020a1709067fd300b00a3bf7aaf9a2si457189ejs.437.2024.02.09.05.17.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 05:17:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59347-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EXcj3iuY; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-59347-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59347-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id B1EE71F25990 for ; Fri, 9 Feb 2024 13:17:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4FF7638398; Fri, 9 Feb 2024 13:16:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EXcj3iuY" 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 DEB5037716; Fri, 9 Feb 2024 13:16:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707484605; cv=none; b=aA6iiyr1cKDRQV7S2dfGLjSoehCjQeVIFglN/MrJZXaejmNO9DFBkHL7FH1TpxLg0tSF8f9r37HR2eOvWNHlEUr1hdtVvWOiQa9B7I8M1Zkwz33GF47iVjkN+mBxwy3FtCFu88PEk3zm85u2/PXHTMsZVr0yUxTaFm4p5cUq9TQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707484605; c=relaxed/simple; bh=qhOoCQNzPzHiOCmjwCButX1WGPZUV4R16n68RDJmqt8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OUwOMMaDgyHF6RLW/TmEjElvPkYiMf/r68VBdHxSieRUgw4gJzLcwIdEQHm5fovftTRcXz5GOVMG5YV9EVR4yt6daGGMguOEP/8PEot0gwuHeC3zQkINRNc87+PZb3qRWl3k0tpmXobHRSCHZhWHAGRvpbMCKjntWznMUTqpA6w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EXcj3iuY; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5cdf76cde78so668885a12.1; Fri, 09 Feb 2024 05:16:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707484603; x=1708089403; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rDApktuVCr/Bgtqf/JWCLMMqtiZv/VT6n1DxWHxTHaM=; b=EXcj3iuYmobodLEoGWEJRxop6W1lZlhGPW69eWIGPFlBqLx3UD9HQlphKSgDCr7juo x5LdcgcIzYdxIHsGq7zrZUxn4/F6LVhUdx84MhsBz7iMbAfWmskX9JsuxyAD/AFxMxiJ dGo0bsCGKF0rQ3YpkTNKmv6xlbiH9222qnrbam13pK4oqlr0BYNmjqtMTituFhMYnWF4 QX8cxc1kxtQDDGo3t5GESdx6Whs7vH4HWamzYcdD2EEMvPs3F1NDQ+nhNZIXlMJSiA8Z KMMTMZsW1cJprm2Zm8P2keXKBbNWWHFookYsR5a8JkiUbJ8MM1YKkYqWxNwiIv5SdZLD sTUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707484603; x=1708089403; 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=rDApktuVCr/Bgtqf/JWCLMMqtiZv/VT6n1DxWHxTHaM=; b=R2uZUYXX6WGT8VZfy2qzg0SmmgmvYUH64iYPGD5NQ4Rej730U2koEVhFz55dg/MYZG Q/5o4mshWi5bEfNdPM1O8BDa3bPmv0x4OC6evwaSR3alXakeX6NDHz1IUwemvKvyHsDS 9/MAfrkMV7pQz161RJSTBIG2bT9xY18t2krW7uA8WwYRpZU8q3H8M1APgOFP78J9ssto uUMauxlNoXu1yNSC9jyZEs6OomepPnejS7tQSdLXHI4kKWVWZnzTFISwBO7IokRfXa4C kAA6KcXodMroIK2ujSy4oa0ANWZlQfEQK6VFBukVPyz51FE3byxAnAU3K0oA1yF0G3YH dF6Q== X-Forwarded-Encrypted: i=1; AJvYcCW6MwGJwnCmqZmj+C71R+HydxVVdI+4BARwgwo3EK31J3H/xe1/0MlcjYdMmVEP+e1bI3kCV6WwsDESE8zIFGQYMW2FhtupADGFjekeg6WPeibcfBxJ8qvGxJIFvuibBQkv/An25wDaXw== X-Gm-Message-State: AOJu0YzZkEVM+fRGeJYBtN+4cNrRWQdWjwct7f/65NBFfI6skiOytoQH 6p2bnKaZ8gtnzVVwmxSjVEeRIex269MeJF8ObAeSh3aLNVZRISjq X-Received: by 2002:a17:90b:1d82:b0:296:a13c:8f84 with SMTP id pf2-20020a17090b1d8200b00296a13c8f84mr1250435pjb.33.1707484603168; Fri, 09 Feb 2024 05:16:43 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWxM2ydgQESyUHQ+CSJwn5oQ8r7qDl74zOftXmtLBlNQ+huAHMs9px8efhFI8gYBX0NVOgBOlbfX0ZRixgzl1fxUnivF3AJh9iRrXsAfBBWkoxu5GM4eiZc5QXtm3XGS91WRGXnL4ezWAeJKBlcVRGi3CJad63sx/FOe2eWFejn5WHM0u7embCcXxuJifoOQSSxu9jsNYklfc/g1136ZI8tNNI+pgfllFZQ+vgcn8AUS3IVGThilkYs1eAjhG/KHvfXrjOULVjhM6rRK1Xi95yG6+klcNrxbE9KPH+WmXvuKRCYB1W4ZbkoewX/JEy9i1RiwF9ol1XYZ8h03mC5G9p2TrsHlysRbdJu2EGAyA== Received: from met-Virtual-Machine.. ([131.107.1.159]) by smtp.gmail.com with ESMTPSA id sk12-20020a17090b2dcc00b00296540086a5sm1713246pjb.23.2024.02.09.05.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 05:16:42 -0800 (PST) From: meetakshisetiyaoss@gmail.com To: sfrench@samba.org, pc@manguebit.com, ronniesahlberg@gmail.com, sprasad@microsoft.com, nspmangalore@gmail.com, tom@talpey.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, samba-technical@lists.samba.org, bharathsm.hsk@gmail.com Cc: Meetakshi Setiya Subject: [PATCH 3/3] smb: client: retry compound request without reusing lease Date: Fri, 9 Feb 2024 08:15:52 -0500 Message-Id: <20240209131552.471765-3-meetakshisetiyaoss@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240209131552.471765-1-meetakshisetiyaoss@gmail.com> References: <20240209131552.471765-1-meetakshisetiyaoss@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Meetakshi Setiya There is a shortcoming in the current implementation of the file lease mechanism exposed when the lease keys were attempted to be reused for unlink, rename and set_path_size operations for a client. As per MS-SMB2, lease keys are associated with the file name. Linux smb client maintains lease keys with the inode. If the file has any hardlinks, it is possible that the lease for a file be wrongly reused for an operation on the hardlink or vice versa. In these cases, the mentioned compound operations fail with STATUS_INVALID_PARAMETER. This patch adds a fallback to the old mechanism of not sending any lease with these compound operations if the request with lease key fails with STATUS_INVALID_PARAMETER. Resending the same request without lease key should not hurt any functionality, but might impact performance especially in cases where the error is not because of the usage of wrong lease key and we might end up doing an extra roundtrip. Signed-off-by: Meetakshi Setiya --- fs/smb/client/smb2inode.c | 41 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 69f3442c5b96..c0d099a9e1ee 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -154,6 +154,17 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, } /* if there is an existing lease, reuse it */ + + /* + * note: files with hardlinks cause unexpected behaviour. As per MS-SMB2, + * lease keys are associated with the filepath. We are maintaining lease keys + * with the inode on the client. If the file has hardlinks, it is possible + * that the lease for a file be reused for an operation on its hardlink or + * vice versa. + * As a workaround, send request using an existing lease key and if the server + * returns STATUS_INVALID_PARAMETER, which maps to EINVAL, send the request + * again without the lease. + */ if (dentry) { inode = d_inode(dentry); if (CIFS_I(inode)->lease_granted && server->ops->get_lease_key) { @@ -867,11 +878,20 @@ int smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, struct cifs_sb_info *cifs_sb, struct dentry *dentry) { - return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, + int rc = smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, ACL_NO_MODE, NULL, &(int){SMB2_OP_DELETE}, 1, NULL, NULL, NULL, dentry); + if (rc == -EINVAL) { + cifs_dbg(FYI, "invalid lease key, resending request without lease"); + rc = smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, + CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, + ACL_NO_MODE, NULL, + &(int){SMB2_OP_DELETE}, 1, + NULL, NULL, NULL, NULL); + } + return rc; } static int smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, @@ -912,8 +932,14 @@ int smb2_rename_path(const unsigned int xid, drop_cached_dir_by_name(xid, tcon, from_name, cifs_sb); cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile); - return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, + int rc = smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, co, DELETE, SMB2_OP_RENAME, cfile, source_dentry); + if (rc == -EINVAL) { + cifs_dbg(FYI, "invalid lease key, resending request without lease"); + rc = smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, + co, DELETE, SMB2_OP_RENAME, cfile, NULL); + } + return rc; } int smb2_create_hardlink(const unsigned int xid, @@ -942,11 +968,20 @@ smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, in_iov.iov_base = &eof; in_iov.iov_len = sizeof(eof); cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile); - return smb2_compound_op(xid, tcon, cifs_sb, full_path, + int rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_WRITE_DATA, FILE_OPEN, 0, ACL_NO_MODE, &in_iov, &(int){SMB2_OP_SET_EOF}, 1, cfile, NULL, NULL, dentry); + if (rc == -EINVAL) { + cifs_dbg(FYI, "invalid lease key, resending request without lease"); + rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, + FILE_WRITE_DATA, FILE_OPEN, + 0, ACL_NO_MODE, &in_iov, + &(int){SMB2_OP_SET_EOF}, 1, + cfile, NULL, NULL, NULL); + } + return rc; } int -- 2.39.2