Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 34afb82

Browse files
committed
Merge tag '6.10-rc6-smb3-server-fixes' of git://git.samba.org/ksmbd
Pull smb server fixes from Steve French: - fix access flags to address fuse incompatibility - fix device type returned by get filesystem info * tag '6.10-rc6-smb3-server-fixes' of git://git.samba.org/ksmbd: ksmbd: discard write access to the directory open ksmbd: return FILE_DEVICE_DISK instead of super magic
2 parents 920bc84 + e2e33ca commit 34afb82

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

fs/smb/common/smb2pdu.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,40 @@ struct smb2_query_directory_rsp {
917917
__u8 Buffer[];
918918
} __packed;
919919

920+
/* DeviceType Flags */
921+
#define FILE_DEVICE_CD_ROM 0x00000002
922+
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
923+
#define FILE_DEVICE_DFS 0x00000006
924+
#define FILE_DEVICE_DISK 0x00000007
925+
#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
926+
#define FILE_DEVICE_FILE_SYSTEM 0x00000009
927+
#define FILE_DEVICE_NAMED_PIPE 0x00000011
928+
#define FILE_DEVICE_NETWORK 0x00000012
929+
#define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
930+
#define FILE_DEVICE_NULL 0x00000015
931+
#define FILE_DEVICE_PARALLEL_PORT 0x00000016
932+
#define FILE_DEVICE_PRINTER 0x00000018
933+
#define FILE_DEVICE_SERIAL_PORT 0x0000001b
934+
#define FILE_DEVICE_STREAMS 0x0000001e
935+
#define FILE_DEVICE_TAPE 0x0000001f
936+
#define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
937+
#define FILE_DEVICE_VIRTUAL_DISK 0x00000024
938+
#define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
939+
940+
/* Device Characteristics */
941+
#define FILE_REMOVABLE_MEDIA 0x00000001
942+
#define FILE_READ_ONLY_DEVICE 0x00000002
943+
#define FILE_FLOPPY_DISKETTE 0x00000004
944+
#define FILE_WRITE_ONCE_MEDIA 0x00000008
945+
#define FILE_REMOTE_DEVICE 0x00000010
946+
#define FILE_DEVICE_IS_MOUNTED 0x00000020
947+
#define FILE_VIRTUAL_VOLUME 0x00000040
948+
#define FILE_DEVICE_SECURE_OPEN 0x00000100
949+
#define FILE_CHARACTERISTIC_TS_DEVICE 0x00001000
950+
#define FILE_CHARACTERISTIC_WEBDAV_DEVICE 0x00002000
951+
#define FILE_PORTABLE_DEVICE 0x00004000
952+
#define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL 0x00020000
953+
920954
/*
921955
* Maximum number of iovs we need for a set-info request.
922956
* The largest one is rename/hardlink

fs/smb/server/smb2pdu.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,15 +2051,22 @@ int smb2_tree_connect(struct ksmbd_work *work)
20512051
* @access: file access flags
20522052
* @disposition: file disposition flags
20532053
* @may_flags: set with MAY_ flags
2054+
* @is_dir: is creating open flags for directory
20542055
*
20552056
* Return: file open flags
20562057
*/
20572058
static int smb2_create_open_flags(bool file_present, __le32 access,
20582059
__le32 disposition,
2059-
int *may_flags)
2060+
int *may_flags,
2061+
bool is_dir)
20602062
{
20612063
int oflags = O_NONBLOCK | O_LARGEFILE;
20622064

2065+
if (is_dir) {
2066+
access &= ~FILE_WRITE_DESIRE_ACCESS_LE;
2067+
ksmbd_debug(SMB, "Discard write access to a directory\n");
2068+
}
2069+
20632070
if (access & FILE_READ_DESIRED_ACCESS_LE &&
20642071
access & FILE_WRITE_DESIRE_ACCESS_LE) {
20652072
oflags |= O_RDWR;
@@ -3167,7 +3174,9 @@ int smb2_open(struct ksmbd_work *work)
31673174

31683175
open_flags = smb2_create_open_flags(file_present, daccess,
31693176
req->CreateDisposition,
3170-
&may_flags);
3177+
&may_flags,
3178+
req->CreateOptions & FILE_DIRECTORY_FILE_LE ||
3179+
(file_present && S_ISDIR(d_inode(path.dentry)->i_mode)));
31713180

31723181
if (!test_tree_conn_flag(tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
31733182
if (open_flags & (O_CREAT | O_TRUNC)) {
@@ -5314,8 +5323,13 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work,
53145323

53155324
info = (struct filesystem_device_info *)rsp->Buffer;
53165325

5317-
info->DeviceType = cpu_to_le32(stfs.f_type);
5318-
info->DeviceCharacteristics = cpu_to_le32(0x00000020);
5326+
info->DeviceType = cpu_to_le32(FILE_DEVICE_DISK);
5327+
info->DeviceCharacteristics =
5328+
cpu_to_le32(FILE_DEVICE_IS_MOUNTED);
5329+
if (!test_tree_conn_flag(work->tcon,
5330+
KSMBD_TREE_CONN_FLAG_WRITABLE))
5331+
info->DeviceCharacteristics |=
5332+
cpu_to_le32(FILE_READ_ONLY_DEVICE);
53195333
rsp->OutputBufferLength = cpu_to_le32(8);
53205334
break;
53215335
}

0 commit comments

Comments
 (0)