From patchwork Wed Jan 1 18:08:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleh Nykyforchyn X-Patchwork-Id: 13924243 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 A75D9383A5; Wed, 1 Jan 2025 17:05:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735751151; cv=none; b=m/hiIAYaiIGXis3fHjcnc97okvs2fQAvKIF9uCgQAw3AlP22CftOO1fIFeVaXJLsPPTv9jJ7jVNQ7u7reqbtDarmMOV0ycUkD3Mc6g/N3Gy8TYtLEowWXTUUWaHuq/bT1KRHV9918K/WoiTfLEzEknAhlMEYHq7TpqtL6YIZXrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735751151; c=relaxed/simple; bh=feFWZW3rkzOtU7RfQnwUIGVEN7+7bZAkc/w06X3jcdM=; h=MIME-Version:From:Date:Message-ID:Subject:To:Cc:Content-Type; b=nXxu+6t5+tPWeJad292KnA7bNOiSOeL8CGTAyI0HQorbRlRxdS8ysKyRgnANw/XMt2NGSjFt/lzgFzdwKaTSh1RhAMFoNwNgZ8F9ZJv/S0n68xzWY2nfxLohp0t7lCKbtaEe95W7I0IZDZJoejMQb88ekRCmxXs1uWk1CuAAK6k= 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=e3wIQi44; arc=none smtp.client-ip=209.85.208.182 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="e3wIQi44" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-30229d5b229so114954691fa.0; Wed, 01 Jan 2025 09:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735751147; x=1736355947; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=feFWZW3rkzOtU7RfQnwUIGVEN7+7bZAkc/w06X3jcdM=; b=e3wIQi44P+Jm0L7FEzYvt0LHtZPLfcBdQK2S9NzyojZjohzVaBQEg3H6MldFagDcYl voeAepGHryxO4btK64uCsR214f9eAvjfMH11fLpklA4LXP1Kd1eK9Y7n9lq6p0iAR2PJ GHAtIur8EQ8qHpA5/2noGDn4DoF7gC+VDWMfb2VBPIHMogypyGAT9Ly9Lviv2VVVALBp 0vf6syQVgGCNb2fbKAbXC2DDyaVMzpGE1TKkKmyfZVLL3mDe2FnmrqzP0kiBcuqoIJdU 2r/HnFUjhaviTTset1GodfdWRaOs7HOsX6QGi6pmCT7SO4EvcKzAjVgEXUHlqFpd7Fao Pl7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735751147; x=1736355947; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=feFWZW3rkzOtU7RfQnwUIGVEN7+7bZAkc/w06X3jcdM=; b=WSKvsDGZQsx7JkvQDNf1ul3DWpCN0o+AWEowJGLxIxPgVXehlQyVhlSZojQ+RWxSBi xb/zhdZ6hn9cU+irWpFFvMeKfxmr7KOxiByBMk6QNBGB+0DPF0JJ7nqkud78mTsRBofA e5DdxeLk0F7DI58fuxVTXnDpBI26XSNSAOgFsEWX9tz2lZg1IplhBUbVObp4crkrBOt6 OkZhplC4abp1y9VyypvgDzHGe5hW5U50Fu0u5Z0sVZUbHDXgZgYusK8bycITx4otgOMF jxMdoiz6C3/MV2visun+8rpLevKuyHmf6mTpdE89LOp1WkOLMA/Q2u23nki/vAuNlda8 OT7A== X-Gm-Message-State: AOJu0YwzxEnGZFiam05O+yxXgDsDUu6Zr4uFJa3ceDuVR3/Wn88aacnH Yo3mLqzuXMNmKi795cNHaCpger5dhz//XMDNGj6PN85nxahQ1oFKZOuTVN5RsB4E0+cEYmQKkkj DjuKVyiPcouDAuXhjT5/yt0szp53X1w== X-Gm-Gg: ASbGncuDr27FAbhWpcpEKtTgwkt/NoYH0l1+5R7h9mVe6uejywAVNeISR4fDckdiQBC 78D+6clWKt1oQ+jA+o7hmF9Pgg8tnQm/K9O5vcQ== X-Google-Smtp-Source: AGHT+IEo0bo4Yodqf4QD4aYOmZ/S3HQH4TfRqlMDRbYTNOgOmwseVmLgPbkViXYZ3Augr3T+AS4kVcIrirwSl2n6xPw= X-Received: by 2002:a05:6512:3a90:b0:540:2a76:584b with SMTP id 2adb3069b0e04-54229581e83mr13244695e87.36.1735751146576; Wed, 01 Jan 2025 09:05:46 -0800 (PST) Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Oleh Nykyforchyn Date: Wed, 1 Jan 2025 20:08:06 +0200 Message-ID: Subject: Bug in getting file attributes with SMB3.1.1 and posix To: linux-cifs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Steve French Hello, I encountered a funny bug when a share is mounted with vers=3.1.1, posix,... If a file size has bits 0x410 = ATTR_DIRECTORY | ATTR_REPARSE = 1040 set, then the file is regarded as a directory and its open fails. A simplest test example is any file 1040 bytes long. The cause of this bug is that Attributes field in smb2_file_all_info struct occupies the same place that EndOfFile field in smb311_posix_qinfo, and sometimes the latter struct is incorrectly processed as if it was the first one. I attach an example patch that solves the problem for me, obviously not ready for submission, but just to show which places in the code are subject to problems. The patch is against linux-6.12.6 kernel, but, AFAICS, nothing has changed since then in relevant places. If I have guessed more or less correctly what the intended functionality is, please feel free to use my patch as a basis for corrections. Best regards Olen Nykyforchyn --- linux-6.12.6/fs/smb/client/reparse.h.orig 2024-12-28 15:37:32.252621378 +0200 +++ linux-6.12.6/fs/smb/client/reparse.h 2024-12-28 15:51:00.004654390 +0200 @@ -108,6 +108,16 @@ return ret; } +static inline bool smb311_open_data_reparse(struct cifs_open_info_data *data) +{ + struct smb311_posix_qinfo *posix_fi = &data->posix_fi; + u32 tag = le32_to_cpu(posix_fi->ReparseTag); + bool ret; + + ret = data->reparse_point || tag; + return ret; +} + bool cifs_reparse_point_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, struct cifs_open_info_data *data); --- linux-6.12.6/fs/smb/client/inode.c.orig 2024-12-28 15:47:56.603646895 +0200 +++ linux-6.12.6/fs/smb/client/inode.c 2024-12-30 18:19:52.816039798 +0200 @@ -845,7 +845,7 @@ fattr->cf_mode = wire_mode_to_posix(le32_to_cpu(info->Mode), fattr->cf_cifsattrs & ATTR_DIRECTORY); - if (cifs_open_data_reparse(data) && + if (smb311_open_data_reparse(data) && cifs_reparse_point_to_fattr(cifs_sb, fattr, data)) goto out_reparse; @@ -976,7 +976,10 @@ rc = PTR_ERR(path); goto cgfi_exit; } - cifs_open_info_to_fattr(&fattr, &data, inode->i_sb); + if (tcon->posix_extensions) + smb311_posix_info_to_fattr(&fattr, &data, inode->i_sb); + else + cifs_open_info_to_fattr(&fattr, &data, inode->i_sb); if (fattr.cf_flags & CIFS_FATTR_DELETE_PENDING) cifs_mark_open_handles_for_deleted_file(inode, path); break; @@ -1176,7 +1179,7 @@ break; case IO_REPARSE_TAG_INTERNAL: rc = 0; - if (le32_to_cpu(data->fi.Attributes) & ATTR_DIRECTORY) { + if (tcon->posix_extensions || (le32_to_cpu(data->fi.Attributes) & ATTR_DIRECTORY)) { cifs_create_junction_fattr(fattr, sb); goto out; } @@ -1250,12 +1253,12 @@ * since we have to check if its reparse tag matches a known * special file type e.g. symlink or fifo or char etc. */ - if (cifs_open_data_reparse(data)) { + if (cifs_open_data_reparse(data)) rc = reparse_info_to_fattr(data, sb, xid, tcon, - full_path, fattr); - } else { + full_path, fattr); + else cifs_open_info_to_fattr(fattr, data, sb); - } + cifs_dbg(FYI, "cifs data to fattr, rc=%d\n", rc); if (!rc && *inode && (fattr->cf_flags & CIFS_FATTR_DELETE_PENDING)) cifs_mark_open_handles_for_deleted_file(*inode, full_path); @@ -1385,6 +1388,8 @@ cifs_dbg(FYI, "No need to revalidate cached inode sizes\n"); return 0; } + else + cifs_dbg(FYI, "Getting cifs attributes for %s\n", full_path); rc = cifs_get_fattr(data, sb, xid, fid, &fattr, inode, full_path); if (rc) @@ -1431,7 +1436,7 @@ switch (rc) { case 0: - if (cifs_open_data_reparse(data)) { + if (smb311_open_data_reparse(data)) { rc = reparse_info_to_fattr(data, sb, xid, tcon, full_path, fattr); } else { @@ -1484,6 +1489,8 @@ cifs_dbg(FYI, "No need to revalidate cached inode sizes\n"); return 0; } + else + cifs_dbg(FYI, "Getting smb3 posix attributes for %s\n", full_path); rc = smb311_posix_get_fattr(data, &fattr, full_path, sb, xid); if (rc)