Skip to content

Commit 0812340

Browse files
Paulo AlcantaraSteve French
authored andcommitted
smb: client: handle max length for SMB symlinks
We can't use PATH_MAX for SMB symlinks because (1) Windows Server will fail FSCTL_SET_REPARSE_POINT with STATUS_IO_REPARSE_DATA_INVALID when input buffer is larger than 16K, as specified in MS-FSA 2.1.5.10.37. (2) The client won't be able to parse large SMB responses that includes SMB symlink path within SMB2_CREATE or SMB2_IOCTL responses. Fix this by defining a maximum length value (4060) for SMB symlinks that both client and server can handle. Cc: David Howells <[email protected]> Cc: [email protected] Signed-off-by: Paulo Alcantara (Red Hat) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 9f544d2 commit 0812340

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

fs/smb/client/reparse.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ int smb2_create_reparse_symlink(const unsigned int xid, struct inode *inode,
3535
u16 len, plen;
3636
int rc = 0;
3737

38+
if (strlen(symname) > REPARSE_SYM_PATH_MAX)
39+
return -ENAMETOOLONG;
40+
3841
sym = kstrdup(symname, GFP_KERNEL);
3942
if (!sym)
4043
return -ENOMEM;
@@ -64,7 +67,7 @@ int smb2_create_reparse_symlink(const unsigned int xid, struct inode *inode,
6467
if (rc < 0)
6568
goto out;
6669

67-
plen = 2 * UniStrnlen((wchar_t *)path, PATH_MAX);
70+
plen = 2 * UniStrnlen((wchar_t *)path, REPARSE_SYM_PATH_MAX);
6871
len = sizeof(*buf) + plen * 2;
6972
buf = kzalloc(len, GFP_KERNEL);
7073
if (!buf) {

fs/smb/client/reparse.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "fs_context.h"
1313
#include "cifsglob.h"
1414

15+
#define REPARSE_SYM_PATH_MAX 4060
16+
1517
/*
1618
* Used only by cifs.ko to ignore reparse points from files when client or
1719
* server doesn't support FSCTL_GET_REPARSE_POINT.

0 commit comments

Comments
 (0)