Skip to content

Commit ebaf546

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
SMB3: Clean up query symlink when reparse point
Two of the common symlink formats use reparse points (unlike mfsymlinks and also unlike the SMB1 posix extensions). This is the first part of the fixes to allow these reparse points (NFS style and Windows symlinks) to be resolved properly as symlinks by the client. Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 6a54b2e commit ebaf546

4 files changed

Lines changed: 118 additions & 17 deletions

File tree

‎fs/cifs/cifsglob.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ struct smb_version_operations {
355355
struct cifs_sb_info *);
356356
/* query symlink target */
357357
int (*query_symlink)(const unsigned int, struct cifs_tcon *,
358-
const char *, char **, struct cifs_sb_info *);
358+
struct cifs_sb_info *, const char *,
359+
char **, bool);
359360
/* open a file for non-posix mounts */
360361
int (*open)(const unsigned int, struct cifs_open_parms *,
361362
__u32 *, FILE_ALL_INFO *);

‎fs/cifs/link.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,16 @@ cifs_get_link(struct dentry *direntry, struct inode *inode,
648648
rc = query_mf_symlink(xid, tcon, cifs_sb, full_path,
649649
&target_path);
650650

651-
if (rc != 0 && server->ops->query_symlink)
652-
rc = server->ops->query_symlink(xid, tcon, full_path,
653-
&target_path, cifs_sb);
651+
if (rc != 0 && server->ops->query_symlink) {
652+
struct cifsInodeInfo *cifsi = CIFS_I(inode);
653+
bool reparse_point = false;
654+
655+
if (cifsi->cifsAttrs & ATTR_REPARSE)
656+
reparse_point = true;
657+
658+
rc = server->ops->query_symlink(xid, tcon, cifs_sb, full_path,
659+
&target_path, reparse_point);
660+
}
654661

655662
kfree(full_path);
656663
free_xid(xid);

‎fs/cifs/smb1ops.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,8 @@ cifs_unix_dfs_readlink(const unsigned int xid, struct cifs_tcon *tcon,
950950

951951
static int
952952
cifs_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
953-
const char *full_path, char **target_path,
954-
struct cifs_sb_info *cifs_sb)
953+
struct cifs_sb_info *cifs_sb, const char *full_path,
954+
char **target_path, bool is_reparse_point)
955955
{
956956
int rc;
957957
int oplock = 0;
@@ -960,6 +960,11 @@ cifs_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
960960

961961
cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
962962

963+
if (is_reparse_point) {
964+
cifs_dbg(VFS, "reparse points not handled for SMB1 symlinks\n");
965+
return -EOPNOTSUPP;
966+
}
967+
963968
/* Check for unix extensions */
964969
if (cap_unix(tcon->ses)) {
965970
rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, target_path,

‎fs/cifs/smb2ops.c‎

Lines changed: 99 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,46 +2390,129 @@ smb2_get_dfs_refer(const unsigned int xid, struct cifs_ses *ses,
23902390

23912391
static int
23922392
smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
2393-
const char *full_path, char **target_path,
2394-
struct cifs_sb_info *cifs_sb)
2393+
struct cifs_sb_info *cifs_sb, const char *full_path,
2394+
char **target_path, bool is_reparse_point)
23952395
{
23962396
int rc;
2397-
__le16 *utf16_path;
2397+
__le16 *utf16_path = NULL;
23982398
__u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
23992399
struct cifs_open_parms oparms;
24002400
struct cifs_fid fid;
24012401
struct kvec err_iov = {NULL, 0};
24022402
struct smb2_err_rsp *err_buf = NULL;
2403-
int resp_buftype;
24042403
struct smb2_symlink_err_rsp *symlink;
24052404
unsigned int sub_len;
24062405
unsigned int sub_offset;
24072406
unsigned int print_len;
24082407
unsigned int print_offset;
2408+
int flags = 0;
2409+
struct smb_rqst rqst[3];
2410+
int resp_buftype[3];
2411+
struct kvec rsp_iov[3];
2412+
struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
2413+
struct kvec io_iov[SMB2_IOCTL_IOV_SIZE];
2414+
struct kvec close_iov[1];
2415+
struct smb2_create_rsp *create_rsp;
2416+
struct smb2_ioctl_rsp *ioctl_rsp;
2417+
char *ioctl_buf;
2418+
u32 plen;
24092419

24102420
cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
24112421

2422+
if (smb3_encryption_required(tcon))
2423+
flags |= CIFS_TRANSFORM_REQ;
2424+
2425+
memset(rqst, 0, sizeof(rqst));
2426+
resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
2427+
memset(rsp_iov, 0, sizeof(rsp_iov));
2428+
24122429
utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
24132430
if (!utf16_path)
24142431
return -ENOMEM;
24152432

2433+
/* Open */
2434+
memset(&open_iov, 0, sizeof(open_iov));
2435+
rqst[0].rq_iov = open_iov;
2436+
rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
2437+
2438+
memset(&oparms, 0, sizeof(oparms));
24162439
oparms.tcon = tcon;
24172440
oparms.desired_access = FILE_READ_ATTRIBUTES;
24182441
oparms.disposition = FILE_OPEN;
2442+
24192443
if (backup_cred(cifs_sb))
24202444
oparms.create_options = CREATE_OPEN_BACKUP_INTENT;
24212445
else
24222446
oparms.create_options = 0;
2447+
if (is_reparse_point)
2448+
oparms.create_options = OPEN_REPARSE_POINT;
2449+
24232450
oparms.fid = &fid;
24242451
oparms.reconnect = false;
24252452

2426-
rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_iov,
2427-
&resp_buftype);
2428-
if (!rc)
2429-
SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
2453+
rc = SMB2_open_init(tcon, &rqst[0], &oplock, &oparms, utf16_path);
2454+
if (rc)
2455+
goto querty_exit;
2456+
smb2_set_next_command(tcon, &rqst[0]);
2457+
2458+
2459+
/* IOCTL */
2460+
memset(&io_iov, 0, sizeof(io_iov));
2461+
rqst[1].rq_iov = io_iov;
2462+
rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE;
2463+
2464+
rc = SMB2_ioctl_init(tcon, &rqst[1], fid.persistent_fid,
2465+
fid.volatile_fid, FSCTL_GET_REPARSE_POINT,
2466+
true /* is_fctl */, NULL, 0, CIFSMaxBufSize);
2467+
if (rc)
2468+
goto querty_exit;
2469+
2470+
smb2_set_next_command(tcon, &rqst[1]);
2471+
smb2_set_related(&rqst[1]);
2472+
2473+
2474+
/* Close */
2475+
memset(&close_iov, 0, sizeof(close_iov));
2476+
rqst[2].rq_iov = close_iov;
2477+
rqst[2].rq_nvec = 1;
2478+
2479+
rc = SMB2_close_init(tcon, &rqst[2], COMPOUND_FID, COMPOUND_FID);
2480+
if (rc)
2481+
goto querty_exit;
2482+
2483+
smb2_set_related(&rqst[2]);
2484+
2485+
rc = compound_send_recv(xid, tcon->ses, flags, 3, rqst,
2486+
resp_buftype, rsp_iov);
2487+
2488+
create_rsp = rsp_iov[0].iov_base;
2489+
if (create_rsp && create_rsp->sync_hdr.Status)
2490+
err_iov = rsp_iov[0];
2491+
ioctl_rsp = rsp_iov[1].iov_base;
2492+
2493+
/*
2494+
* Open was successful and we got an ioctl response.
2495+
*/
2496+
if ((rc == 0) && (is_reparse_point)) {
2497+
/* See MS-FSCC 2.3.23 */
2498+
2499+
ioctl_buf = (char *)ioctl_rsp + le32_to_cpu(ioctl_rsp->OutputOffset);
2500+
plen = le32_to_cpu(ioctl_rsp->OutputCount);
2501+
2502+
if (plen + le32_to_cpu(ioctl_rsp->OutputOffset) >
2503+
rsp_iov[1].iov_len) {
2504+
cifs_dbg(VFS, "srv returned invalid ioctl length: %d\n", plen);
2505+
rc = -EIO;
2506+
goto querty_exit;
2507+
}
2508+
2509+
/* Do stuff with ioctl_buf/plen */
2510+
goto querty_exit;
2511+
}
2512+
24302513
if (!rc || !err_iov.iov_base) {
24312514
rc = -ENOENT;
2432-
goto free_path;
2515+
goto querty_exit;
24332516
}
24342517

24352518
err_buf = err_iov.iov_base;
@@ -2469,9 +2552,14 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
24692552
cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
24702553

24712554
querty_exit:
2472-
free_rsp_buf(resp_buftype, err_buf);
2473-
free_path:
2555+
cifs_dbg(FYI, "query symlink rc %d\n", rc);
24742556
kfree(utf16_path);
2557+
SMB2_open_free(&rqst[0]);
2558+
SMB2_ioctl_free(&rqst[1]);
2559+
SMB2_close_free(&rqst[2]);
2560+
free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
2561+
free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
2562+
free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
24752563
return rc;
24762564
}
24772565

0 commit comments

Comments
 (0)