Skip to content

Commit 8e2f6a0

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: fix open failure from block and char device file
char/block device file can't be opened with dentry_open() if device driver is not loaded. Use O_PATH flags for fake opening file to handle it if file is a block or char file. Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent d782d6e commit 8e2f6a0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

fs/smb/server/smb2pdu.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,18 +2052,20 @@ int smb2_tree_connect(struct ksmbd_work *work)
20522052
* @access: file access flags
20532053
* @disposition: file disposition flags
20542054
* @may_flags: set with MAY_ flags
2055-
* @is_dir: is creating open flags for directory
2055+
* @coptions: file creation options
2056+
* @mode: file mode
20562057
*
20572058
* Return: file open flags
20582059
*/
20592060
static int smb2_create_open_flags(bool file_present, __le32 access,
20602061
__le32 disposition,
20612062
int *may_flags,
2062-
bool is_dir)
2063+
__le32 coptions,
2064+
umode_t mode)
20632065
{
20642066
int oflags = O_NONBLOCK | O_LARGEFILE;
20652067

2066-
if (is_dir) {
2068+
if (coptions & FILE_DIRECTORY_FILE_LE || S_ISDIR(mode)) {
20672069
access &= ~FILE_WRITE_DESIRE_ACCESS_LE;
20682070
ksmbd_debug(SMB, "Discard write access to a directory\n");
20692071
}
@@ -2080,7 +2082,7 @@ static int smb2_create_open_flags(bool file_present, __le32 access,
20802082
*may_flags = MAY_OPEN | MAY_READ;
20812083
}
20822084

2083-
if (access == FILE_READ_ATTRIBUTES_LE)
2085+
if (access == FILE_READ_ATTRIBUTES_LE || S_ISBLK(mode) || S_ISCHR(mode))
20842086
oflags |= O_PATH;
20852087

20862088
if (file_present) {
@@ -3175,8 +3177,8 @@ int smb2_open(struct ksmbd_work *work)
31753177
open_flags = smb2_create_open_flags(file_present, daccess,
31763178
req->CreateDisposition,
31773179
&may_flags,
3178-
req->CreateOptions & FILE_DIRECTORY_FILE_LE ||
3179-
(file_present && S_ISDIR(d_inode(path.dentry)->i_mode)));
3180+
req->CreateOptions,
3181+
file_present ? d_inode(path.dentry)->i_mode : 0);
31803182

31813183
if (!test_tree_conn_flag(tcon, KSMBD_TREE_CONN_FLAG_WRITABLE)) {
31823184
if (open_flags & (O_CREAT | O_TRUNC)) {

0 commit comments

Comments
 (0)