platform/kernel/linux-starfive.git
3 years agoksmbd: remove select FS_POSIX_ACL in Kconfig
Namjae Jeon [Thu, 12 Aug 2021 23:15:33 +0000 (08:15 +0900)]
ksmbd: remove select FS_POSIX_ACL in Kconfig

ksmbd is forcing to turn on FS_POSIX_ACL in Kconfig to use vfs acl
functions(posix_acl_alloc, get_acl, set_posix_acl). OpenWRT and other
platform doesn't use acl and this config is disable by default in
kernel. This patch use IS_ENABLED() to know acl config is enable and use
acl function if it is enable.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: use proper errno instead of -1 in smb2_get_ksmbd_tcon()
Namjae Jeon [Thu, 12 Aug 2021 01:18:18 +0000 (10:18 +0900)]
ksmbd: use proper errno instead of -1 in smb2_get_ksmbd_tcon()

Use proper errno instead of -1 in smb2_get_ksmbd_tcon().

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: update the comment for smb2_get_ksmbd_tcon()
Namjae Jeon [Thu, 12 Aug 2021 01:17:39 +0000 (10:17 +0900)]
ksmbd: update the comment for smb2_get_ksmbd_tcon()

Update the comment for smb2_get_ksmbd_tcon().

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: change int data type to boolean
Namjae Jeon [Thu, 12 Aug 2021 01:16:40 +0000 (10:16 +0900)]
ksmbd: change int data type to boolean

Change data type of function that return only 0 or 1 to boolean.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: Fix multi-protocol negotiation
Marios Makassikis [Thu, 12 Aug 2021 01:12:35 +0000 (10:12 +0900)]
ksmbd: Fix multi-protocol negotiation

To negotiate either the SMB2 protocol or SMB protocol, a client must
send a SMB_COM_NEGOTIATE message containing the list of dialects it
supports, to which the server will respond with either a
SMB_COM_NEGOTIATE or a SMB2_NEGOTIATE response.

The current implementation responds with the highest common dialect,
rather than looking explicitly for "SMB 2.???" and "SMB 2.002", as
indicated in [MS-SMB2]:

  [MS-SMB2] 3.3.5.3.1:
    If the server does not implement the SMB 2.1 or 3.x dialect family,
    processing MUST continue as specified in 3.3.5.3.2.

    Otherwise, the server MUST scan the dialects provided for the dialect
    string "SMB 2.???". If the string is not present, continue to section
    3.3.5.3.2. If the string is present, the server MUST respond with an
    SMB2 NEGOTIATE Response as specified in 2.2.4.

  [MS-SMB2] 3.3.5.3.2:
    The server MUST scan the dialects provided for the dialect string "SMB
    2.002". If the string is present, the client understands SMB2, and the
    server MUST respond with an SMB2 NEGOTIATE Response.

This is an issue if a client attempts to negotiate SMB3.1.1 using
a SMB_COM_NEGOTIATE, as it will trigger the following NULL pointer
dereference:

  8<--- cut here ---
  Unable to handle kernel NULL pointer dereference at virtual address 00000000
  pgd = 1917455e
  [00000000] *pgd=00000000
  Internal error: Oops: 17 [#1] ARM
  CPU: 0 PID: 60 Comm: kworker/0:1 Not tainted 5.4.60-00027-g0518c02b5c5b #35
  Hardware name: Marvell Kirkwood (Flattened Device Tree)
  Workqueue: ksmbd-io handle_ksmbd_work
  PC is at ksmbd_gen_preauth_integrity_hash+0x24/0x190
  LR is at smb3_preauth_hash_rsp+0x50/0xa0
  pc : [<802b7044>] lr : [<802d6ac0>] psr: 40000013
  sp : bf199ed8 ip : 00000000 fp : 80d1edb0
  r10: 80a3471b r9 : 8091af16 r8 : 80d70640
  r7 : 00000072 r6 : be95e198 r5 : ca000000 r4 : b97fee00
  r3 : 00000000 r2 : 00000002 r1 : b97fea00 r0 : b97fee00
  Flags: nZcv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
  Control: 0005317f Table: 3e7f4000 DAC: 00000055
  Process kworker/0:1 (pid: 60, stack limit = 0x3dd1fdb4)
  Stack: (0xbf199ed8 to 0xbf19a000)
  9ec0: b97fee00 00000000
  9ee0: be95e198 00000072 80d70640 802d6ac0 b3da2680 b97fea00 424d53ff be95e140
  9f00: b97fee00 802bd7b0 bf10fa58 80128a78 00000000 000001c8 b6220000 bf0b7720
  9f20: be95e198 80d0c410 bf7e2a00 00000000 00000000 be95e19c 80d0c370 80123b90
  9f40: bf0b7720 be95e198 bf0b7720 bf0b7734 80d0c410 bf198000 80d0c424 80d116e0
  9f60: bf10fa58 801240c0 00000000 bf10fa40 bf1463a0 bf198000 bf0b7720 80123ed0
  9f80: bf077ee4 bf10fa58 00000000 80127f80 bf1463a0 80127e88 00000000 00000000
  9fa0: 00000000 00000000 00000000 801010d0 00000000 00000000 00000000 00000000
  9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 00000000 00000000
  [<802b7044>] (ksmbd_gen_preauth_integrity_hash) from [<802d6ac0>] (smb3_preauth_hash_rsp+0x50/0xa0)
  [<802d6ac0>] (smb3_preauth_hash_rsp) from [<802bd7b0>] (handle_ksmbd_work+0x348/0x3f8)
  [<802bd7b0>] (handle_ksmbd_work) from [<80123b90>] (process_one_work+0x160/0x200)
  [<80123b90>] (process_one_work) from [<801240c0>] (worker_thread+0x1f0/0x2e4)
  [<801240c0>] (worker_thread) from [<80127f80>] (kthread+0xf8/0x10c)
  [<80127f80>] (kthread) from [<801010d0>] (ret_from_fork+0x14/0x24)
  Exception stack(0xbf199fb0 to 0xbf199ff8)
  9fa0: 00000000 00000000 00000000 00000000
  9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  9fe0: 00000000 00000000 00000000 00000000 00000013 00000000
  Code: e1855803 e5d13003 e1855c03 e5903094 (e1d330b0)
  ---[ end trace 8d03be3ed09e5699 ]---
  Kernel panic - not syncing: Fatal exception

smb3_preauth_hash_rsp() panics because conn->preauth_info is only allocated
when processing a SMB2 NEGOTIATE request.

Fix this by splitting the smb_protos array into two, each containing
only SMB1 and SMB2 dialects respectively.

While here, make ksmbd_negotiate_smb_dialect() static as it not
called from anywhere else.

Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix an oops in error handling in smb2_open()
Dan Carpenter [Sun, 1 Aug 2021 23:14:03 +0000 (08:14 +0900)]
ksmbd: fix an oops in error handling in smb2_open()

If smb2_get_name() then name is an error pointer.  In the clean up
code, we try to kfree() it and that will lead to an Oops.  Set it to
NULL instead.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: add ipv6_addr_v4mapped check to know if connection from client is ipv4
Namjae Jeon [Tue, 27 Jul 2021 04:25:13 +0000 (13:25 +0900)]
ksmbd: add ipv6_addr_v4mapped check to know if connection from client is ipv4

ksmbd create socket with IPv6 to listen both IPv4 and IPv6 connection
from client. Server should send IP addresses of NICs through network
interface info response. If Client connection is IPv4, Server should
fill IPv4 address in response buffer. But ss_family is always PF_INET6
on IPv6 socket. So This patch add ipv6_addr_v4mapped check to know
client connection is IPv4.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix missing error code in smb2_lock
Namjae Jeon [Tue, 27 Jul 2021 00:40:05 +0000 (09:40 +0900)]
ksmbd: fix missing error code in smb2_lock

Dan report a warning that is missing error code in smb2_lock
from static checker. This patch add error code to avoid static checker
warning.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: use channel signingkey for binding SMB2 session setup
Namjae Jeon [Tue, 27 Jul 2021 00:30:29 +0000 (09:30 +0900)]
ksmbd: use channel signingkey for binding SMB2 session setup

Windows client disconnect connection by wrong signed SMB2 session
setup response on SMB3 multichannel mode.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: don't set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO
Namjae Jeon [Tue, 27 Jul 2021 00:28:10 +0000 (09:28 +0900)]
ksmbd: don't set RSS capable in FSCTL_QUERY_NETWORK_INTERFACE_INFO

ksmbd does not support RSS mode stably.
RSS mode enabling will be set later.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: Return STATUS_OBJECT_PATH_NOT_FOUND if smb2_creat() returns ENOENT
Marios Makassikis [Tue, 27 Jul 2021 00:24:51 +0000 (09:24 +0900)]
ksmbd: Return STATUS_OBJECT_PATH_NOT_FOUND if smb2_creat() returns ENOENT

Both Windows 10's SMB server and samba return STATUS_OBJECT_PATH_NOT_FOUND
when trying to access a nonexistent path.

This fixes Windows 10 File History tool. The latter relies on the server
returning STATUS_OBJECT_PATH_NOT_FOUND to figure out what part of the
target path needs to be created. Returning STATUS_OBJECT_NAME_INVALID
will make it stop and display an error to the user.

Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix -Wstringop-truncation warnings
Hyunchul Lee [Fri, 23 Jul 2021 04:01:06 +0000 (13:01 +0900)]
ksmbd: fix -Wstringop-truncation warnings

Kernel test bot reports the following warnings:

   In function 'ndr_write_string',
       inlined from 'ndr_encode_dos_attr' at fs/ksmbd/ndr.c:136:3:
>> fs/ksmbd/ndr.c:70:2: warning: 'strncpy' destination unchanged after
copying no bytes [-Wstringop-truncation]
      70 |  strncpy(PAYLOAD_HEAD(n), value, sz);
         |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   In function 'ndr_write_string',
       inlined from 'ndr_encode_dos_attr' at fs/ksmbd/ndr.c:134:3:
>> fs/ksmbd/ndr.c:70:2: warning: 'strncpy' output truncated before
terminating nul copying as many bytes from a string as its length
[-Wstringop-truncation]
      70 |  strncpy(PAYLOAD_HEAD(n), value, sz);
         |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fs/ksmbd/ndr.c: In function 'ndr_encode_dos_attr':
   fs/ksmbd/ndr.c:134:3: note: length computed here
     134 |   ndr_write_string(n, hex_attr, strlen(hex_attr));
         |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: Fix potential memory leak in tcp_destroy_socket()
Marios Makassikis [Fri, 23 Jul 2021 03:58:41 +0000 (12:58 +0900)]
ksmbd: Fix potential memory leak in tcp_destroy_socket()

ksmbd_socket must be freed even if kernel_sock_shutdown() somehow fails.

Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: add support for negotiating signing algorithm
Namjae Jeon [Wed, 21 Jul 2021 01:05:53 +0000 (10:05 +0900)]
ksmbd: add support for negotiating signing algorithm

Support for faster packet signing (using GMAC instead of CMAC) can
now be negotiated to some newer servers, including Windows.
See MS-SMB2 section 2.2.3.17.

This patch adds support for sending the new negotiate context with two
supported signing algorithms(AES-CMAC, HMAC-SHA256).
If client add support for AES_GMAC, Server will be supported later
depend on it.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: add negotiate context verification
Namjae Jeon [Wed, 21 Jul 2021 01:03:19 +0000 (10:03 +0900)]
ksmbd: add negotiate context verification

This patch add negotiate context verification code to check bounds.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix typo of MS-SMBD
Namjae Jeon [Fri, 16 Jul 2021 08:16:11 +0000 (17:16 +0900)]
ksmbd: fix typo of MS-SMBD

Fix typo : "MS-KSMBD" => "MS-SMBD".

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: move credit charge verification over smb2 request size verification
Namjae Jeon [Fri, 16 Jul 2021 07:39:54 +0000 (16:39 +0900)]
ksmbd: move credit charge verification over smb2 request size verification

Move credit charge verification over smb2 request size verification
to avoid being skipped.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: set STATUS_INVALID_PARAMETER error status if credit charge is invalid
Namjae Jeon [Fri, 16 Jul 2021 05:52:46 +0000 (14:52 +0900)]
ksmbd: set STATUS_INVALID_PARAMETER error status if credit charge is invalid

MS-SMB2 specification describe :
 If the calculated credit number is greater than the CreditCharge,
 the server MUST fail the request with the error code
 STATUS_INVALID_PARAMETER.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix wrong error status return on session setup
Namjae Jeon [Fri, 16 Jul 2021 05:52:09 +0000 (14:52 +0900)]
ksmbd: fix wrong error status return on session setup

When user insert wrong password, ksmbd return STATUS_INVALID_PARAMETER
error status to client. It will make user confusing whether it is not
password problem. This patch change error status to
STATUS_LOGON_FAILURE. and return STATUS_INSUFFICIENT_RESOURCES if memory
allocation failed on session setup.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix wrong compression context size
Namjae Jeon [Fri, 16 Jul 2021 05:51:30 +0000 (14:51 +0900)]
ksmbd: fix wrong compression context size

Use smb2_compression_ctx instead of smb2_encryption_neg_context.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix typo in comment
Namjae Jeon [Thu, 15 Jul 2021 01:22:20 +0000 (10:22 +0900)]
ksmbd: fix typo in comment

Fix typo "openning" -> "opening".

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix an error message in ksmbd_conn_trasnport_init
Hyunchul Lee [Tue, 13 Jul 2021 06:38:30 +0000 (15:38 +0900)]
ksmbd: fix an error message in ksmbd_conn_trasnport_init

Fix an error message in ksmbd_conn_transport_init().

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: set RDMA capability for FSCTL_QUERY_NETWORK_INTERFACE_INFO
Hyunchul Lee [Tue, 13 Jul 2021 07:09:34 +0000 (16:09 +0900)]
ksmbd: set RDMA capability for FSCTL_QUERY_NETWORK_INTERFACE_INFO

set RDMA capability for
FSCTL_QUERY_NETWORK_INTERFACE_INFO.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix unused err value in smb2_lock
Namjae Jeon [Tue, 13 Jul 2021 08:17:28 +0000 (17:17 +0900)]
ksmbd: fix unused err value in smb2_lock

CID 1502845 (#1 of 1): Unused value (UNUSED_VALUE)
value_overwrite: Overwriting previous write to err with value from
vfs_lock_file(filp, 0U, rlock, NULL).
6880                err = vfs_lock_file(filp, 0, rlock, NULL);
6881                if (err)
6882                        pr_err("rollback unlock fail : %d\n", err);

Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix memory leak in ksmbd_vfs_get_sd_xattr()
Namjae Jeon [Tue, 13 Jul 2021 08:12:41 +0000 (17:12 +0900)]
ksmbd: fix memory leak in ksmbd_vfs_get_sd_xattr()

Add free acl.sd_buf and n.data on error handling in
ksmbd_vfs_get_sd_xattr().

Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove unneeded check_context_err
Namjae Jeon [Tue, 13 Jul 2021 00:59:34 +0000 (09:59 +0900)]
ksmbd: remove unneeded check_context_err

Coverity Scan seems to report false alarm.

*** CID 1505930:    (USE_AFTER_FREE)
/fs/ksmbd/smb2pdu.c: 2527 in smb2_open()
>>> CID 1505930:    (USE_AFTER_FREE)
>>> Passing freed pointer "context" as an argument to
>>> "check_context_err".

This patch remove unneeded check_context_err to make coverity scan
happy.

Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: handle error cases first in smb2_create_sd_buffers
Hyunchul Lee [Fri, 9 Jul 2021 08:06:34 +0000 (17:06 +0900)]
ksmbd: handle error cases first in smb2_create_sd_buffers

For code cleanup, handle error cases first in
smb2_create_sd_buffers().

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: make smb2_find_context_vals return NULL if not found
Hyunchul Lee [Fri, 9 Jul 2021 08:06:33 +0000 (17:06 +0900)]
ksmbd: make smb2_find_context_vals return NULL if not found

instead of -ENOENT, make smb2_find_context_vals
return NULL if the given context cannot be found.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: uninterruptible wait for a file being unlocked
Hyunchul Lee [Sat, 10 Jul 2021 00:34:20 +0000 (09:34 +0900)]
ksmbd: uninterruptible wait for a file being unlocked

the wait can be canceled by SMB2_CANCEL, SMB2_CLOSE,
SMB2_LOGOFF, disconnection or shutdown, we don't have
to use wait_event_interruptible.

And this remove the warning from Coverity:

CID 1502834 (#1 of 1): Unused value (UNUSED_VALUE)
returned_value: Assigning value from ksmbd_vfs_posix_lock_wait(flock)
to err here, but that stored value is overwritten before it can be used.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: free ksmbd_lock when file is closed
Hyunchul Lee [Sat, 10 Jul 2021 07:22:41 +0000 (16:22 +0900)]
ksmbd: free ksmbd_lock when file is closed

Append ksmbd_lock into the connection's
lock list and the ksmbd_file's lock list.
And when a file is closed, detach ksmbd_lock
from these lists and free it.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix the running request count decrement
Hyunchul Lee [Sat, 10 Jul 2021 00:31:08 +0000 (09:31 +0900)]
ksmbd: fix the running request count decrement

decrement the count of running requests after
sending the last response for multi-response
requests.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: use kasprintf() in ksmbd_vfs_xattr_stream_name()
Dan Carpenter [Wed, 7 Jul 2021 10:15:32 +0000 (13:15 +0300)]
ksmbd: use kasprintf() in ksmbd_vfs_xattr_stream_name()

Simplify the code by using kasprintf().  This also silences a Smatch
warning:

    fs/ksmbd/vfs.c:1725 ksmbd_vfs_xattr_stream_name()
    warn: inconsistent indenting

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: delete some stray tabs
Dan Carpenter [Wed, 7 Jul 2021 10:15:40 +0000 (13:15 +0300)]
ksmbd: delete some stray tabs

These lines are intended one tab too far.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: change data type of volatile/persistent id to u64
Namjae Jeon [Thu, 8 Jul 2021 03:32:27 +0000 (12:32 +0900)]
ksmbd: change data type of volatile/persistent id to u64

This patch change data type of volatile/persistent id to u64 to make
issue from idr_find and idr_remove(). !HAS_FILE_ID check will protect
integer overflow issue from idr_find and idr_remove().

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix memory leak in smb_inherit_dacl()
Namjae Jeon [Wed, 7 Jul 2021 06:01:21 +0000 (15:01 +0900)]
ksmbd: fix memory leak in smb_inherit_dacl()

Add two labels to fix memory leak in smb_inherit_dacl().

Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix memory leak smb2_populate_readdir_entry()
Namjae Jeon [Wed, 7 Jul 2021 05:57:24 +0000 (14:57 +0900)]
ksmbd: fix memory leak smb2_populate_readdir_entry()

Add missing kfree(conv_name) on error path.

Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix read on the uninitialized send_ctx
Namjae Jeon [Wed, 7 Jul 2021 05:56:44 +0000 (14:56 +0900)]
ksmbd: fix read on the uninitialized send_ctx

If st->status is not SMB_DIRECT_CS_CONNECTED, It will jump done label
and accessing the uninitialized send_ctxi by smb_direct_flush_send_list
will cause kernel oops. This patch just return -ENOTCONN to avoid it.

Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove unneeded NULL check in for_each_netdev
Namjae Jeon [Wed, 7 Jul 2021 05:55:31 +0000 (14:55 +0900)]
ksmbd: remove unneeded NULL check in for_each_netdev

netdev can never be NULL in for_each_netdev loop.
This patch remove unneeded NULL check.

Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: Fix read on the uninitialized pointer sess
Colin Ian King [Tue, 6 Jul 2021 12:05:01 +0000 (13:05 +0100)]
ksmbd: Fix read on the uninitialized pointer sess

There is a error handling case that passes control to label out_err
without pointer sess being assigned a value. The unassigned pointer
may be any garbage value and so the test of rc < 0 && sess maybe
true leading to sess being passed to the call to ksmbd_session_destroy.
Fix this by setting sess to NULL in this corner case.

Addresses-Coverity: ("Uninitialized pointer read")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: call mnt_user_ns once in a function
Hyunchul Lee [Sat, 3 Jul 2021 03:10:36 +0000 (12:10 +0900)]
ksmbd: call mnt_user_ns once in a function

Avoid calling mnt_user_ns() many time in
a function.

Cc: Christoph Hellwig <hch@infradead.org>
Cc: Christian Brauner <christian@brauner.io>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix kernel oops in ksmbd_rpc_ioctl/rap()
Namjae Jeon [Fri, 2 Jul 2021 23:00:06 +0000 (08:00 +0900)]
ksmbd: fix kernel oops in ksmbd_rpc_ioctl/rap()

"ksmbd: remove macros in transport_ipc.c" commit change msg to req in
ksmbd_rpc_ioctl/rap(). This will cause kernel oops when running smbclient
-L test.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: add user namespace support
Hyunchul Lee [Wed, 30 Jun 2021 09:25:53 +0000 (18:25 +0900)]
ksmbd: add user namespace support

For user namespace support, call vfs functions
with struct user_namespace got from struct path.

This patch have been tested mannually as below.

Create an id-mapped mount using the mount-idmapped utility
(https://github.com/brauner/mount-idmapped).
$ mount-idmapped --map-mount b:1003:1002:1 /home/foo <EXPORT DIR>/foo
(the user, "foo" is 1003, and the user "bar" is 1002).

And  mount the export directory using cifs with the user, "bar".
succeed to create/delete/stat/read/write files and directory in
the <EXPORT DIR>/foo. But fail with a bind mount for /home/foo.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: replace struct dentry with struct path in some function's arguments
Hyunchul Lee [Wed, 30 Jun 2021 09:25:52 +0000 (18:25 +0900)]
ksmbd: replace struct dentry with struct path in some function's arguments

For user namespace support, we need to pass
struct user_namespace with struct dentry
to some functions. For reducing the number
of arguments, replace the struct dentry with
struct path in these functions.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: reorder and document on-disk and netlink structures in headers
Namjae Jeon [Tue, 29 Jun 2021 05:52:00 +0000 (14:52 +0900)]
ksmbd: reorder and document on-disk and netlink structures in headers

Reorder and document on-disk and netlink structures in headers.

This is a userspace ABI to communicate data between ksmbd and user IPC
daemon using netlink. This is added to track and cache user account DB
and share configuration info from userspace.

 - KSMBD_EVENT_HEARTBEAT_REQUEST(ksmbd_heartbeat)
   This event is to check whether user IPC daemon is alive. If user IPC
   daemon is dead, ksmbd keep existing connection till disconnecting and
   new connection will be denied.

 - KSMBD_EVENT_STARTING_UP(ksmbd_startup_request)
   This event is to receive the information that initializes the ksmbd
   server from the user IPC daemon and to start the server. The global
   section parameters are given from smb.conf as initialization
   information.

 - KSMBD_EVENT_SHUTTING_DOWN(ksmbd_shutdown_request)
   This event is to shutdown ksmbd server.

 - KSMBD_EVENT_LOGIN_REQUEST/RESPONSE(ksmbd_login_request/response)
   This event is to get user account info to user IPC daemon.

 - KSMBD_EVENT_SHARE_CONFIG_REQUEST/RESPONSE
   (ksmbd_share_config_request/response)
   This event is to get net share configuration info.

 - KSMBD_EVENT_TREE_CONNECT_REQUEST/RESPONSE
   (ksmbd_tree_connect_request/response)
   This event is to get session and tree connect info.

 - KSMBD_EVENT_TREE_DISCONNECT_REQUEST(ksmbd_tree_disconnect_request)
   This event is to send tree disconnect info to user IPC daemon.

 - KSMBD_EVENT_LOGOUT_REQUEST(ksmbd_logout_request)
   This event is to send logout request to user IPC daemon.

 - KSMBD_EVENT_RPC_REQUEST/RESPONSE(ksmbd_rpc_command)
   This event is to make DCE/RPC request like srvsvc, wkssvc, lsarpc,
   samr to be processed in userspace.

 - KSMBD_EVENT_SPNEGO_AUTHEN_REQUEST/RESPONSE
   (ksmbd_spnego_authen_request/response)
   This event is to make kerberos authentication to be processed in
   userspace.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: change server config string index to enumeration
Namjae Jeon [Wed, 30 Jun 2021 00:39:15 +0000 (09:39 +0900)]
ksmbd: change server config string index to enumeration

Change server config string index to enumeration.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: change server state type macro to enumeration
Namjae Jeon [Wed, 30 Jun 2021 00:38:46 +0000 (09:38 +0900)]
ksmbd: change server state type macro to enumeration

Change server state type macro to enumeration.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: change sid types to enumeration
Namjae Jeon [Wed, 30 Jun 2021 00:38:13 +0000 (09:38 +0900)]
ksmbd: change sid types to enumeration

Change sid types to enumeration.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: change ACE types to enumeration
Namjae Jeon [Wed, 30 Jun 2021 00:37:43 +0000 (09:37 +0900)]
ksmbd: change ACE types to enumeration

Change ACE types to enumeration.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove SMB1 oplock level macros
Namjae Jeon [Wed, 30 Jun 2021 00:37:09 +0000 (09:37 +0900)]
ksmbd: remove SMB1 oplock level macros

ksmbd does not support SMB1. This patch remove SMB1 oplock level macros.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: opencode to remove ATTR_FP macro
Namjae Jeon [Tue, 29 Jun 2021 00:24:31 +0000 (09:24 +0900)]
ksmbd: opencode to remove ATTR_FP macro

Opencode to remove ATTR_FP macro.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: use ksmbd_vfs_lock_parent to get stable parent dentry
Namjae Jeon [Tue, 29 Jun 2021 00:23:56 +0000 (09:23 +0900)]
ksmbd: use ksmbd_vfs_lock_parent to get stable parent dentry

Use ksmbd_vfs_lock_parent to get stable parent dentry and remove
PARENT_INODE macro.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: opencode to remove FP_INODE macro
Namjae Jeon [Tue, 29 Jun 2021 00:20:13 +0000 (09:20 +0900)]
ksmbd: opencode to remove FP_INODE macro

Opencode to remove FP_INODE macro.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix dentry racy with rename()
Namjae Jeon [Tue, 29 Jun 2021 00:22:16 +0000 (09:22 +0900)]
ksmbd: fix dentry racy with rename()

Using ->d_name can be broken due to races with rename().
So use %pd with ->d_name to print filename and In other cases,
use it under ->d_lock.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: Relax credit_charge check in smb2_validate_credit_charge()
Marios Makassikis [Sat, 26 Jun 2021 13:56:48 +0000 (22:56 +0900)]
ksmbd: Relax credit_charge check in smb2_validate_credit_charge()

smb2_validate_credit_charge() checks the CreditCharge field in the
request is valid with regards to the payload size.

The current implementation rejects requests with CreditCharge = 0 and a
payload < 64K, even though they should be accepted.

Set CreditCharge to a minimum value of 1 to avoid rejecting such
requests. This matches what samba4 does.

Fixes share enumeration for jcifs-ng clients.

Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: allow PROTECTED_DACL_SECINFO and UNPROTECTED_DACL_SECINFO addition information...
Namjae Jeon [Mon, 28 Jun 2021 06:26:37 +0000 (15:26 +0900)]
ksmbd: allow PROTECTED_DACL_SECINFO and UNPROTECTED_DACL_SECINFO addition information in smb2 set info security

"cifsd: Fix regression in smb2_get_info" patch cause that dacl doesn't
work. windows send smb2 set info security with PROTECTED_DACL_SECINFO to
control dacl. But previous patch doesn't allow it.
This patch add PROTECTED_DACL_SECINFO and UNPROTECTED_DACL_SECINFO
addtional information flags in check.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: replace request and respone buffer macro with inline functions
Namjae Jeon [Fri, 25 Jun 2021 04:43:37 +0000 (13:43 +0900)]
ksmbd: replace request and respone buffer macro with inline functions

replace request and respone buffer macro with inline functions.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: replace SMB_DIRECT_TRANS macro with inline function
Namjae Jeon [Fri, 25 Jun 2021 04:43:01 +0000 (13:43 +0900)]
ksmbd: replace SMB_DIRECT_TRANS macro with inline function

replace SMB_DIRECT_TRANS macro with inline function.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove and replace macros with inline functions in smb_common.h
Hyunchul Lee [Fri, 25 Jun 2021 02:53:26 +0000 (11:53 +0900)]
ksmbd: remove and replace macros with inline functions in smb_common.h

Remove and replace macros with inline functions
in smb_common.h

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove getting worker state macros
Hyunchul Lee [Thu, 24 Jun 2021 22:02:10 +0000 (07:02 +0900)]
ksmbd: remove getting worker state macros

Remove getting worker state macros

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: replace PAYLOAD_HEAD with inline function
Hyunchul Lee [Thu, 24 Jun 2021 22:02:09 +0000 (07:02 +0900)]
ksmbd: replace PAYLOAD_HEAD with inline function

Replace PAYLOAD_HEAD with inline function.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: replace KSMBD_ALIGN with kernel ALIGN macro
Hyunchul Lee [Thu, 24 Jun 2021 22:02:08 +0000 (07:02 +0900)]
ksmbd: replace KSMBD_ALIGN with kernel ALIGN macro

Replace KSMBD_ALIGN with kernel ALIGN macro

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: replace BUFFER_NR_PAGES with inline function
Hyunchul Lee [Thu, 24 Jun 2021 22:02:07 +0000 (07:02 +0900)]
ksmbd: replace BUFFER_NR_PAGES with inline function

Replace BUFFER_NR_PAGES with inline function

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove macros in transport_ipc.c
Hyunchul Lee [Thu, 24 Jun 2021 22:02:06 +0000 (07:02 +0900)]
ksmbd: remove macros in transport_ipc.c

Remove macros in transport_ipc.c

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: set MAY_* flags together with open flags
Hyunchul Lee [Wed, 23 Jun 2021 04:48:24 +0000 (13:48 +0900)]
ksmbd: set MAY_* flags together with open flags

set MAY_* flags together with open flags and
remove ksmbd_vfs_inode_permission().

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: factor out a ksmbd_vfs_lock_parent helper
Hyunchul Lee [Wed, 23 Jun 2021 02:07:43 +0000 (11:07 +0900)]
ksmbd: factor out a ksmbd_vfs_lock_parent helper

Factor out a self-contained helper to
get stable parent dentry.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoMAINTAINERS: rename cifsd to ksmbd
Namjae Jeon [Thu, 24 Jun 2021 00:20:03 +0000 (09:20 +0900)]
MAINTAINERS: rename cifsd to ksmbd

Rename cifsd to ksmbd and update Sergey's mail address.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: move fs/cifsd to fs/ksmbd
Namjae Jeon [Thu, 24 Jun 2021 01:34:11 +0000 (10:34 +0900)]
ksmbd: move fs/cifsd to fs/ksmbd

Move fs/cifsd to fs/ksmbd and rename the remaining cifsd name to ksmbd.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: use f_bsize in FS_SECTOR_SIZE_INFORMATION
Namjae Jeon [Tue, 22 Jun 2021 07:20:47 +0000 (16:20 +0900)]
ksmbd: use f_bsize in FS_SECTOR_SIZE_INFORMATION

Use f_bsize in FS_SECTOR_SIZE_INFORMATION to avoid the access the block
layer.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove unneeded NULL check in the list iterator
Namjae Jeon [Tue, 22 Jun 2021 07:16:45 +0000 (16:16 +0900)]
ksmbd: remove unneeded NULL check in the list iterator

Remove unneeded NULL check in the list iterator. And use
list_for_each_entry_safe instead of list_for_each_safe.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: use f_bsize instead of q->limits.logical_block_size
Namjae Jeon [Sat, 26 Jun 2021 13:32:34 +0000 (22:32 +0900)]
ksmbd: use f_bsize instead of q->limits.logical_block_size

Use f_bsize instead of q->limits.logical_block_size.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: change stream type macro to enumeration
Namjae Jeon [Tue, 22 Jun 2021 04:26:24 +0000 (13:26 +0900)]
ksmbd: change stream type macro to enumeration

Change stream type macro to enumeration and move it to vfs.h.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: opencode posix acl functions instead of wrappers
Namjae Jeon [Tue, 22 Jun 2021 02:42:29 +0000 (11:42 +0900)]
ksmbd: opencode posix acl functions instead of wrappers

Add select FS_POSIX_ACL in Kconfig and then opencode posix acl functions
instead of wrappers

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: factor out a ksmbd_validate_entry_in_use helper from __ksmbd_vfs_rename
Namjae Jeon [Fri, 18 Jun 2021 01:20:24 +0000 (10:20 +0900)]
ksmbd: factor out a ksmbd_validate_entry_in_use helper from __ksmbd_vfs_rename

Factor out a self-contained helper to find sub file/dir in use.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: opencode to avoid trivial wrappers
Namjae Jeon [Tue, 22 Jun 2021 02:06:11 +0000 (11:06 +0900)]
ksmbd: opencode to avoid trivial wrappers

Opencode to avoid trivial wrappers that just make the code hard to
follow.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove ksmbd_err/info
Namjae Jeon [Mon, 28 Jun 2021 06:23:19 +0000 (15:23 +0900)]
ksmbd: remove ksmbd_err/info

Use the pr_fmt built into pr_*. and use pr_err/info after removing
wrapper ksmbd_err/info.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: replace KSMBD_SHARE_CONFIG_PATH with inline function
Namjae Jeon [Fri, 18 Jun 2021 01:42:32 +0000 (10:42 +0900)]
ksmbd: replace KSMBD_SHARE_CONFIG_PATH with inline function

replace KSMBD_SHARE_CONFIG_PATH with inline function.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove ____ksmbd_align in ksmbd_server.h
Namjae Jeon [Fri, 18 Jun 2021 01:41:42 +0000 (10:41 +0900)]
ksmbd: remove ____ksmbd_align in ksmbd_server.h

None of structures needs the attribute.
So remove ____ksmbd_align in ksmbd_server.h.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove unneeded FIXME comment
Namjae Jeon [Fri, 18 Jun 2021 01:40:56 +0000 (10:40 +0900)]
ksmbd: remove unneeded FIXME comment

Remove unneeded FIXME comment.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix overly long line
Namjae Jeon [Fri, 18 Jun 2021 01:30:46 +0000 (10:30 +0900)]
ksmbd: fix overly long line

Fix overly long line.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: use goto instead of duplicating the resoure cleanup in ksmbd_open_fd
Namjae Jeon [Fri, 18 Jun 2021 01:29:56 +0000 (10:29 +0900)]
ksmbd: use goto instead of duplicating the resoure cleanup in ksmbd_open_fd

Use goto instead of duplicating the resoure cleanup in ksmbd_open_fd.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: use list_for_each_entry instead of list_for_each
Namjae Jeon [Fri, 18 Jun 2021 01:28:52 +0000 (10:28 +0900)]
ksmbd: use list_for_each_entry instead of list_for_each

Use list_for_each_entry instead of list_for_each.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove ksmbd_vfs_copy_file_range
Namjae Jeon [Fri, 18 Jun 2021 01:28:00 +0000 (10:28 +0900)]
ksmbd: remove ksmbd_vfs_copy_file_range

vfs_copy_file_range and cifs client already does this type of fallback,
so this is dead code.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: initialize variables on the declaration
Namjae Jeon [Fri, 18 Jun 2021 01:18:34 +0000 (10:18 +0900)]
ksmbd: initialize variables on the declaration

Initialize variables on the declaration.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: remove cache read/trans buffer support
Namjae Jeon [Fri, 18 Jun 2021 01:17:37 +0000 (10:17 +0900)]
ksmbd: remove cache read/trans buffer support

As vmalloc performance improvement patch for big allocation is merged into
linux kernel, This feature is no longer not needed.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: add support for SMB3 multichannel
Namjae Jeon [Fri, 18 Jun 2021 01:04:19 +0000 (10:04 +0900)]
ksmbd: add support for SMB3 multichannel

Add support for SMB3 multichannel. It will be enable by setting
'server multi channel support = yes' in smb.conf.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agoksmbd: fix kfree of uninitialized pointer oid
Colin Ian King [Fri, 18 Jun 2021 00:54:53 +0000 (09:54 +0900)]
ksmbd: fix kfree of uninitialized pointer oid

Currently function ksmbd_neg_token_init_mech_type can kfree an
uninitialized pointer oid when the call to asn1_oid_decode fails when
vlen is out of range. All the other failure cases in function
asn1_oid_decode set *oid to NULL on an error, so fix the issue by
ensuring the vlen out of range error also nullifies the pointer.

Addresses-Coverity: ("Uninitialized pointer read")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: append ksmbd prefix into names for asn1 decoder
Hyunchul Lee [Wed, 9 Jun 2021 01:06:57 +0000 (10:06 +0900)]
cifsd: append ksmbd prefix into names for asn1 decoder

Because functions and variables generated from
ASN1 compiler aren't static, append ksmbd prefix
into thoses to avoid link errors.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: remove duplicated argument
Wan Jiabing [Mon, 7 Jun 2021 04:54:32 +0000 (12:54 +0800)]
cifsd: remove duplicated argument

Fix the following coccicheck warning:
./fs/cifsd/smb2pdu.c:1713:27-41: duplicated argument to & or |

FILE_DELETE_LE is duplicated. Remove one and reorder argument to
make coding style reasonable.

Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: fix possible compile error for asn1.c
Hyunchul Lee [Sun, 6 Jun 2021 02:42:25 +0000 (11:42 +0900)]
cifsd: fix possible compile error for asn1.c

spnego_negtokeninit.asn1.h and spnego_negtokentarg.asn1.h
have to be generated before asn1.o is compiled.
Because of parallel build, the dependency could be broken,
we need to specify the dependency in Makefile.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: set epoch in smb2_lease_break response
Namjae Jeon [Mon, 7 Jun 2021 00:22:22 +0000 (09:22 +0900)]
cifsd: set epoch in smb2_lease_break response

When running generic/591 after smb2 leases is enable, all smb2 lease ack
requests failed in ksmbd. because cifs client seems to support only smb2
v2 lease. So cifs doesn't update lease state in ack request if epoch is
not set in smb2 lease break request from ksmbd. epoch is used for smb2
v2 leases. So this patch add smb2 create v2 lease context and set
increased epoch in smb2 lease break response.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: fix list_add double add BUG_ON trap in setup_async_work()
Namjae Jeon [Mon, 7 Jun 2021 00:08:45 +0000 (09:08 +0900)]
cifsd: fix list_add double add BUG_ON trap in setup_async_work()

BUG_ON trap is coming when running xfstests generic/591 and
smb2 leases = yes in smb.conf.

[  597.224978] list_add double add: new=ffff9110d292bb20,
prev=ffff9110d292bb20, next=ffff9110d6c389e8.
[  597.225073] ------------[ cut here ]------------
[  597.225077] kernel BUG at lib/list_debug.c:31!
[  597.225090] invalid opcode: 0000 [#1] SMP PTI
[  597.225095] CPU: 2 PID: 501 Comm: kworker/2:3 Tainted: G           OE
5.13.0-rc1+ #2
[  597.225099] Hardware name: SAMSUNG ELECTRONICS CO., LTD. Samsung
DeskTop System/SAMSUNG_DT1234567890, BIOS P04KBM.022.121023.SK
10/23/2012
[  597.225102] Workqueue: ksmbd-io handle_ksmbd_work [ksmbd]
[  597.225125] RIP: 0010:__list_add_valid+0x66/0x70
[  597.225132] Code: 0b 48 89 c1 4c 89 c6 48 c7 c7 c8 08 c0 95 e8 fd 54
66 00 0f 0b 48 89 f2 4c 89 c1 48 89 fe 48 c7 c7 20 09 c0 95 e8 e6 54 66
00 <0f> 0b 0f 1f 84 00 00 00 00 00 55 48 8b 07 48 b9 00 01 00 00 00 00
[  597.225136] RSP: 0018:ffffb9c9408dbac0 EFLAGS: 00010282
[  597.225139] RAX: 0000000000000058 RBX: ffff9110d292ba40 RCX:
0000000000000000
[  597.225142] RDX: 0000000000000000 RSI: ffff9111da328c30 RDI:
ffff9111da328c30
[  597.225144] RBP: ffffb9c9408dbac0 R08: 0000000000000001 R09:
0000000000000001
[  597.225147] R10: 0000000003dd35ed R11: ffffb9c9408db888 R12:
ffff9110d6c38998
[  597.225149] R13: ffff9110d6c38800 R14: ffff9110d292bb20 R15:
ffff9110d292bb20
[  597.225152] FS:  0000000000000000(0000) GS:ffff9111da300000(0000)
knlGS:0000000000000000
[  597.225155] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  597.225157] CR2: 00007fd1629f84d0 CR3: 00000000c9a12006 CR4:
00000000001706e0
[  597.225160] Call Trace:
[  597.225163]  setup_async_work+0xa2/0x120 [ksmbd]
[  597.225191]  oplock_break+0x396/0x5d0 [ksmbd]
[  597.225206]  smb_grant_oplock+0x7a1/0x900 [ksmbd]
[  597.225218]  ? smb_grant_oplock+0x7a1/0x900 [ksmbd]
[  597.225231]  smb2_open+0xbbb/0x2960 [ksmbd]
[  597.225243]  ? smb2_open+0xbbb/0x2960 [ksmbd]
[  597.225257]  ? find_held_lock+0x35/0xa0
[  597.225261]  ? xa_load+0xaf/0x160
[  597.225268]  handle_ksmbd_work+0x2e0/0x420 [ksmbd]
[  597.225280]  ? handle_ksmbd_work+0x2e0/0x420 [ksmbd]
[  597.225292]  process_one_work+0x25a/0x5d0
[  597.225298]  worker_thread+0x3f/0x3a0
[  597.225302]  ? __kthread_parkme+0x6f/0xa0
[  597.225306]  ? process_one_work+0x5d0/0x5d0
[  597.225309]  kthread+0x142/0x160
[  597.225313]  ? kthread_park+0x90/0x90
[  597.225316]  ret_from_fork+0x22/0x30

same work struct can be add to list in smb_break_all_write_oplock() and
smb_grant_oplock(). If client send invalid lease break ack to server,
This issue can occur by calling both functions.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: fix additional warnings from checkpatch.pl --strict
Namjae Jeon [Tue, 1 Jun 2021 04:18:44 +0000 (13:18 +0900)]
cifsd: fix additional warnings from checkpatch.pl --strict

Fix additional warnings from checkpatch.pl --strict.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: fix potential read overflow in ksmbd_vfs_stream_read()
Namjae Jeon [Mon, 31 May 2021 08:26:43 +0000 (17:26 +0900)]
cifsd: fix potential read overflow in ksmbd_vfs_stream_read()

If *pos or *pos + count is greater than v_len, It will read beyond
the stream_buf buffer. This patch add the check and cut down count with
size of the buffer.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: check return value of ksmbd_vfs_getcasexattr() correctly
Yang Yingliang [Mon, 31 May 2021 08:25:05 +0000 (17:25 +0900)]
cifsd: check return value of ksmbd_vfs_getcasexattr() correctly

If ksmbd_vfs_getcasexattr() returns -ENOMEM, stream_buf is NULL,
it will cause null-ptr-deref when using it to copy memory. So we
need check the return value of ksmbd_vfs_getcasexattr() by comparing
with 0.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: fix memleak in ksmbd_vfs_stream_read()
Yang Yingliang [Sat, 29 May 2021 08:20:57 +0000 (16:20 +0800)]
cifsd: fix memleak in ksmbd_vfs_stream_read()

Before ksmbd_vfs_stream_read() return, memory allocate in
ksmbd_vfs_getcasexattr() need be freed.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: fix memleak in ksmbd_vfs_stream_write()
Yang Yingliang [Sat, 29 May 2021 08:20:56 +0000 (16:20 +0800)]
cifsd: fix memleak in ksmbd_vfs_stream_write()

Before assigning wbuf to stream_buf, memory allocate in
ksmbd_vfs_getcasexattr() need be freed.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: make alignment match open parenthesis
Hyunchul Lee [Sat, 29 May 2021 00:59:59 +0000 (09:59 +0900)]
cifsd: make alignment match open parenthesis

checkpatch.pl complains as the following:

Alignment should match open parenthesis.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: enclose macro variables in parenthesis
Hyunchul Lee [Sat, 29 May 2021 13:46:53 +0000 (22:46 +0900)]
cifsd: enclose macro variables in parenthesis

checkpatch.pl complains as the following:

CHECK: Macro argument 'fp' may be better as '(fp)' to avoid
precedence issues.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: fix Control flow issues in ksmbd_build_ntlmssp_challenge_blob()
Namjae Jeon [Fri, 28 May 2021 22:59:40 +0000 (07:59 +0900)]
cifsd: fix Control flow issues in ksmbd_build_ntlmssp_challenge_blob()

Fix a defect reported by Coverity Scan.

*** CID 1504970:  Control flow issues  (NO_EFFECT)
/fs/cifsd/auth.c: 622 in ksmbd_build_ntlmssp_challenge_blob()
616             name = kmalloc(2 + UNICODE_LEN(len), GFP_KERNEL);
617             if (!name)
618                     return -ENOMEM;
619
620             conv_len = smb_strtoUTF16((__le16 *)name,
ksmbd_netbios_name(), len,
621                                       sess->conn->local_nls);
>>>     CID 1504970:  Control flow issues  (NO_EFFECT)
>>>     This less-than-zero comparison of an unsigned value is never true.
622             if (conv_len < 0 || conv_len > len) {
623                     kfree(name);
624                     return -EINVAL;
625             }
626
627             uni_len = UNICODE_LEN(conv_len);

Reported-by: Coverity Scan <scan-admin@coverity.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
3 years agocifsd: lookup a file with LOOKUP_FOLLOW only if 'follow symlinks = yes'
Hyunchul Lee [Wed, 26 May 2021 09:59:06 +0000 (18:59 +0900)]
cifsd: lookup a file with LOOKUP_FOLLOW only if 'follow symlinks = yes'

Some vfs help functions lookup a file with
LOOKUP_FOLLOW regardless of the "follow symlinks"
option.

Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>