From patchwork Sun Sep 22 04:48:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 13809001 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 428DB746E for ; Sun, 22 Sep 2024 04:48:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726980505; cv=none; b=AjMySOqAY5v6KWdBSIMNp0K8z+uaKKvg+2fh/GqUh99SU+XYUWTzmcWK+DNtzvHqtH7dGVhXBXobs58G3liOjDBNBfb06KZsOukkWpeuwKaV53EGhCHm7vp9W7tYcnOtJZ9HRAiEQHYCBCSJiU+7vHv2SyunG+OTuW5twgEcI+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726980505; c=relaxed/simple; bh=oHHMNeRAQu9NLstWzLmSI0EBBLnamsOJ8Fjm6e8kd9s=; h=MIME-Version:From:Date:Message-ID:Subject:To:Cc:Content-Type; b=Pme0GwaeOWeDkthXAH3O0qjiqxdXgAqmdJCNLgYz5XLk4aORNRgYDE2SLIF+GZNDuLchjpIBddUsdi03AunIdVfGrHv+Sum932cVXtRUg5LBScAMksjpCm5p9n47ZMAri9eQLoYJ5gL2toMyTm00XO3wzH2kJ05NT7tdwF8u8ho= 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=X01vpx4c; arc=none smtp.client-ip=209.85.167.54 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X01vpx4c" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-53567b4c3f4so3501752e87.2 for ; Sat, 21 Sep 2024 21:48:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726980502; x=1727585302; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ve7ook3wQD8EIyjnBvFXXYebcWZemVc3sfN/+ms8WjY=; b=X01vpx4cG+5HgFCxkAoYH7kZgwgKjntDQEMpfW9xlH2LGFDgvUOMXkKtCPSEmyDfeP ujM5DTy8y2qmvkSINSYzh2SCVNWiEMolXbgN/O0uGKQuFOotBl+Bqsm/eAYdSTGvAd3K pR64PkY5ALzuJeeINZDON9GKJWsUkHZsICXr+W6XCqd4cgvuiYtuBuMF6DZ28rWAjMYQ aN2YBcwYsDCffAx8mzzyFVL1N/NLVpMwERSWrPFH4uXT1GfosTij3E5fXg9fs8uR9gPl YkCe8zXn/ZQmz8pRe5V+kxirRW7DI0NbJ80P7nrcQOulsFsMs5SSZWD8BZzL5KmUn2aD AzMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726980502; x=1727585302; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ve7ook3wQD8EIyjnBvFXXYebcWZemVc3sfN/+ms8WjY=; b=sfmVMEEKT9wtCSw+Gd9utWlo+qF29DlNqIyco0opClOhhhCvSxPAWnr9wbvwyisXvB A2rLd8mwnPRWdTDZ2P4+a6jwnaNSKhaD1oq37jJJYo3HY6CC74QOM3yh6xP4J0dISzsc ErettDzevQ+t6Yq5bRJSKWjM4jOFiJ8YtsuCoJgV1QTGGGWPsjaiv0l7QhB6dgqwwrow t4ehn0KO3vbXHQM4zBkR4UGhJ/4Xdty30U2FtkVwowodoP2QvApKS/4yUTypgmZ/i9W3 /AtHln9w82juP7w0wHDabEKH6EdB2Uoo5YzyDCL4uwI4QW72SJHMpc7NIq4DDeUr4gLN a3jg== X-Forwarded-Encrypted: i=1; AJvYcCVeKocILdMLKBfgELWhN+PPVh2srjqVRYPueOhSb3YL5TO8/n2EJP5Zgb8IDt71VMmfKEGhYWCo5b52@vger.kernel.org X-Gm-Message-State: AOJu0Yx4VJ2UhuN0jFlGjtPVZ9g04xKDjt89J20xLbNbLiX7QQQ7kpRD kK89JbgQiotALilyT0tuUAlALHejRgJc3+Pkb/fYNNdZlNp+9z6P7hk/+lZHSXxoE3cgJ3WDyFl LrGWpqwPCAdaz8OGQE+AnnEU2Z0I= X-Google-Smtp-Source: AGHT+IGW7VvHOrZ0um5jX8pkZ8aX3XrxnMGnQixIc2TvGq2fpUwtezzJQ5jZIEAxop253UGnvbRlzH0ff+encly4+Ag= X-Received: by 2002:a05:6512:a8e:b0:536:52c4:e45c with SMTP id 2adb3069b0e04-536ac2f54b4mr3143712e87.31.1726980502072; Sat, 21 Sep 2024 21:48:22 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steve French Date: Sat, 21 Sep 2024 23:48:10 -0500 Message-ID: Subject: [PATCH][SMB3 client] fix incorrect mode bits reported for stat of directories with read only attribute To: Maxim Patlasov , CIFS Cc: Paulo Alcantara In investigating a problem that Maxim pointed out (with rmdir when file has read only attribute set - which will be fixed with a different patch), we noticed a bug with "stat" of directories when readonly. See attached fix. Commands like "chmod 0444" mark a file readonly via the attribute flag (when mapping of mode bits into the ACL are not set, or POSIX extensions are not negotiated), but they were not reported correctly for stat of directories (they were reported ok for files and for "ls"). See example below: root:~# ls /mnt2 -l total 12 drwxr-xr-x 2 root root 0 Sep 21 18:03 normaldir -rwxr-xr-x 1 root root 0 Sep 21 23:24 normalfile dr-xr-xr-x 2 root root 0 Sep 21 17:55 readonly-dir -r-xr-xr-x 1 root root 209716224 Sep 21 18:15 readonly-file root:~# stat -c %a /mnt2/readonly-dir 755 root:~# stat -c %a /mnt2/readonly-file 555 This fixes the stat of directories when ATTR_READONLY is set (in cases where the mode can not be obtained other ways). See below stat output with patch applied: root:~# stat -c %a /mnt2/readonly-dir 555 From 385a86fa4704ec11f19564ea42eaf677b283e6ce Mon Sep 17 00:00:00 2001 From: Steve French Date: Sat, 21 Sep 2024 23:28:32 -0500 Subject: [PATCH] smb3: fix incorrect mode displayed for read-only files Commands like "chmod 0444" mark a file readonly via the attribute flag (when mapping of mode bits into the ACL are not set, or POSIX extensions are not negotiated), but they were not reported correctly for stat of directories (they were reported ok for files and for "ls"). See example below: root:~# ls /mnt2 -l total 12 drwxr-xr-x 2 root root 0 Sep 21 18:03 normaldir -rwxr-xr-x 1 root root 0 Sep 21 23:24 normalfile dr-xr-xr-x 2 root root 0 Sep 21 17:55 readonly-dir -r-xr-xr-x 1 root root 209716224 Sep 21 18:15 readonly-file root:~# stat -c %a /mnt2/readonly-dir 755 root:~# stat -c %a /mnt2/readonly-file 555 This fixes the stat of directories when ATTR_READONLY is set (in cases where the mode can not be obtained other ways). root:~# stat -c %a /mnt2/readonly-dir 555 Cc: stable@vger.kernel.org Signed-off-by: Steve French --- fs/smb/client/inode.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 73e2e6c230b7..3ccf3e69bec6 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -800,10 +800,6 @@ static void cifs_open_info_to_fattr(struct cifs_fattr *fattr, fattr->cf_mode = S_IFREG | cifs_sb->ctx->file_mode; fattr->cf_dtype = DT_REG; - /* clear write bits if ATTR_READONLY is set */ - if (fattr->cf_cifsattrs & ATTR_READONLY) - fattr->cf_mode &= ~(S_IWUGO); - /* * Don't accept zero nlink from non-unix servers unless * delete is pending. Instead mark it as unknown. @@ -816,6 +812,10 @@ static void cifs_open_info_to_fattr(struct cifs_fattr *fattr, } } + /* clear write bits if ATTR_READONLY is set */ + if (fattr->cf_cifsattrs & ATTR_READONLY) + fattr->cf_mode &= ~(S_IWUGO); + out_reparse: if (S_ISLNK(fattr->cf_mode)) { if (likely(data->symlink_target)) @@ -1233,11 +1233,14 @@ static int cifs_get_fattr(struct cifs_open_info_data *data, __func__, rc); goto out; } - } - - /* fill in remaining high mode bits e.g. SUID, VTX */ - if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) + } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) + /* fill in remaining high mode bits e.g. SUID, VTX */ cifs_sfu_mode(fattr, full_path, cifs_sb, xid); + else if (!(tcon->posix_extensions)) + /* clear write bits if ATTR_READONLY is set */ + if (fattr->cf_cifsattrs & ATTR_READONLY) + fattr->cf_mode &= ~(S_IWUGO); + /* check for Minshall+French symlinks */ if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) { -- 2.43.0