Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
smb: client: handle max length for SMB symlinks
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pcacjr authored and Steve French committed Nov 21, 2024
1 parent 9f544d2 commit 0812340
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fs/smb/client/reparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ int smb2_create_reparse_symlink(const unsigned int xid, struct inode *inode,
u16 len, plen;
int rc = 0;

if (strlen(symname) > REPARSE_SYM_PATH_MAX)
return -ENAMETOOLONG;

sym = kstrdup(symname, GFP_KERNEL);
if (!sym)
return -ENOMEM;
Expand Down Expand Up @@ -64,7 +67,7 @@ int smb2_create_reparse_symlink(const unsigned int xid, struct inode *inode,
if (rc < 0)
goto out;

plen = 2 * UniStrnlen((wchar_t *)path, PATH_MAX);
plen = 2 * UniStrnlen((wchar_t *)path, REPARSE_SYM_PATH_MAX);
len = sizeof(*buf) + plen * 2;
buf = kzalloc(len, GFP_KERNEL);
if (!buf) {
Expand Down
2 changes: 2 additions & 0 deletions fs/smb/client/reparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "fs_context.h"
#include "cifsglob.h"

#define REPARSE_SYM_PATH_MAX 4060

/*
* Used only by cifs.ko to ignore reparse points from files when client or
* server doesn't support FSCTL_GET_REPARSE_POINT.
Expand Down

0 comments on commit 0812340

Please sign in to comment.