1. 18 9月, 2021 5 次提交
  2. 17 9月, 2021 1 次提交
  3. 16 9月, 2021 1 次提交
    • L
      qnx4: avoid stringop-overread errors · b7213ffa
      Linus Torvalds 提交于
      The qnx4 directory entries are 64-byte blocks that have different
      contents depending on the a status byte that is in the last byte of the
      block.
      
      In particular, a directory entry can be either a "link info" entry with
      a 48-byte name and pointers to the real inode information, or an "inode
      entry" with a smaller 16-byte name and the full inode information.
      
      But the code was written to always just treat the directory name as if
      it was part of that "inode entry", and just extend the name to the
      longer case if the status byte said it was a link entry.
      
      That work just fine and gives the right results, but now that gcc is
      tracking data structure accesses much more, the code can trigger a
      compiler error about using up to 48 bytes (the long name) in a structure
      that only has that shorter name in it:
      
         fs/qnx4/dir.c: In function ‘qnx4_readdir’:
         fs/qnx4/dir.c:51:32: error: ‘strnlen’ specified bound 48 exceeds source size 16 [-Werror=stringop-overread]
            51 |                         size = strnlen(de->di_fname, size);
               |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
         In file included from fs/qnx4/qnx4.h:3,
                          from fs/qnx4/dir.c:16:
         include/uapi/linux/qnx4_fs.h:45:25: note: source object declared here
            45 |         char            di_fname[QNX4_SHORT_NAME_MAX];
               |                         ^~~~~~~~
      
      which is because the source code doesn't really make this whole "one of
      two different types" explicit.
      
      Fix this by introducing a very explicit union of the two types, and
      basically explaining to the compiler what is really going on.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      b7213ffa
  4. 15 9月, 2021 3 次提交
  5. 14 9月, 2021 6 次提交
  6. 13 9月, 2021 9 次提交
    • D
      afs: Fix updating of i_blocks on file/dir extension · 9d37e1ca
      David Howells 提交于
      When an afs file or directory is modified locally such that the total file
      size is extended, i_blocks needs to be recalculated too.
      
      Fix this by making afs_write_end() and afs_edit_dir_add() call
      afs_set_i_size() rather than setting inode->i_size directly as that also
      recalculates inode->i_blocks.
      
      This can be tested by creating and writing into directories and files and
      then examining them with du.  Without this change, directories show a 4
      blocks (they start out at 2048 bytes) and files show 0 blocks; with this
      change, they should show a number of blocks proportional to the file size
      rounded up to 1024.
      
      Fixes: 31143d5d ("AFS: implement basic file write support")
      Fixes: 63a4681f ("afs: Locally edit directory data for mkdir/create/unlink/...")
      Reported-by: NMarkus Suvanto <markus.suvanto@gmail.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Reviewed-by: NMarc Dionne <marc.dionne@auristor.com>
      Tested-by: NMarkus Suvanto <markus.suvanto@gmail.com>
      cc: linux-afs@lists.infradead.org
      Link: https://lore.kernel.org/r/163113612442.352844.11162345591911691150.stgit@warthog.procyon.org.uk/
      9d37e1ca
    • D
      afs: Fix corruption in reads at fpos 2G-4G from an OpenAFS server · b537a3c2
      David Howells 提交于
      AFS-3 has two data fetch RPC variants, FS.FetchData and FS.FetchData64, and
      Linux's afs client switches between them when talking to a non-YFS server
      if the read size, the file position or the sum of the two have the upper 32
      bits set of the 64-bit value.
      
      This is a problem, however, since the file position and length fields of
      FS.FetchData are *signed* 32-bit values.
      
      Fix this by capturing the capability bits obtained from the fileserver when
      it's sent an FS.GetCapabilities RPC, rather than just discarding them, and
      then picking out the VICED_CAPABILITY_64BITFILES flag.  This can then be
      used to decide whether to use FS.FetchData or FS.FetchData64 - and also
      FS.StoreData or FS.StoreData64 - rather than using upper_32_bits() to
      switch on the parameter values.
      
      This capabilities flag could also be used to limit the maximum size of the
      file, but all servers must be checked for that.
      
      Note that the issue does not exist with FS.StoreData - that uses *unsigned*
      32-bit values.  It's also not a problem with Auristor servers as its
      YFS.FetchData64 op uses unsigned 64-bit values.
      
      This can be tested by cloning a git repo through an OpenAFS client to an
      OpenAFS server and then doing "git status" on it from a Linux afs
      client[1].  Provided the clone has a pack file that's in the 2G-4G range,
      the git status will show errors like:
      
      	error: packfile .git/objects/pack/pack-5e813c51d12b6847bbc0fcd97c2bca66da50079c.pack does not match index
      	error: packfile .git/objects/pack/pack-5e813c51d12b6847bbc0fcd97c2bca66da50079c.pack does not match index
      
      This can be observed in the server's FileLog with something like the
      following appearing:
      
      Sun Aug 29 19:31:39 2021 SRXAFS_FetchData, Fid = 2303380852.491776.3263114, Host 192.168.11.201:7001, Id 1001
      Sun Aug 29 19:31:39 2021 CheckRights: len=0, for host=192.168.11.201:7001
      Sun Aug 29 19:31:39 2021 FetchData_RXStyle: Pos 18446744071815340032, Len 3154
      Sun Aug 29 19:31:39 2021 FetchData_RXStyle: file size 2400758866
      ...
      Sun Aug 29 19:31:40 2021 SRXAFS_FetchData returns 5
      
      Note the file position of 18446744071815340032.  This is the requested file
      position sign-extended.
      
      Fixes: b9b1f8d5 ("AFS: write support fixes")
      Reported-by: NMarkus Suvanto <markus.suvanto@gmail.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Reviewed-by: NMarc Dionne <marc.dionne@auristor.com>
      Tested-by: NMarkus Suvanto <markus.suvanto@gmail.com>
      cc: linux-afs@lists.infradead.org
      cc: openafs-devel@openafs.org
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=214217#c9 [1]
      Link: https://lore.kernel.org/r/951332.1631308745@warthog.procyon.org.uk/
      b537a3c2
    • D
      afs: Try to avoid taking RCU read lock when checking vnode validity · 4fe6a946
      David Howells 提交于
      Try to avoid taking the RCU read lock when checking the validity of a
      vnode's callback state.  The only thing it's needed for is to pin the
      parent volume's server list whilst we search it to find the record of the
      server we're currently using to see if it has been reinitialised (ie. it
      sent us a CB.InitCallBackState* RPC).
      
      Do this by the following means:
      
       (1) Keep an additional per-cell counter (fs_s_break) that's incremented
           each time any of the fileservers in the cell reinitialises.
      
           Since the new counter can be accessed without RCU from the vnode, we
           can check that first - and only if it differs, get the RCU read lock
           and check the volume's server list.
      
       (2) Replace afs_get_s_break_rcu() with afs_check_server_good() which now
           indicates whether the callback promise is still expected to be present
           on the server.  This does the checks as described in (1).
      
       (3) Restructure afs_check_validity() to take account of the change in (2).
      
           We can also get rid of the valid variable and just use the need_clear
           variable with the addition of the afs_cb_break_no_promise reason.
      
       (4) afs_check_validity() probably shouldn't be altering vnode->cb_v_break
           and vnode->cb_s_break when it doesn't have cb_lock exclusively locked.
      
           Move the change to vnode->cb_v_break to __afs_break_callback().
      
           Delegate the change to vnode->cb_s_break to afs_select_fileserver()
           and set vnode->cb_fs_s_break there also.
      
       (5) afs_validate() no longer needs to get the RCU read lock around its
           call to afs_check_validity() - and can skip the call entirely if we
           don't have a promise.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Tested-by: NMarkus Suvanto <markus.suvanto@gmail.com>
      cc: linux-afs@lists.infradead.org
      Link: https://lore.kernel.org/r/163111669583.283156.1397603105683094563.stgit@warthog.procyon.org.uk/
      4fe6a946
    • D
      afs: Fix mmap coherency vs 3rd-party changes · 6e0e99d5
      David Howells 提交于
      Fix the coherency management of mmap'd data such that 3rd-party changes
      become visible as soon as possible after the callback notification is
      delivered by the fileserver.  This is done by the following means:
      
       (1) When we break a callback on a vnode specified by the CB.CallBack call
           from the server, we queue a work item (vnode->cb_work) to go and
           clobber all the PTEs mapping to that inode.
      
           This causes the CPU to trip through the ->map_pages() and
           ->page_mkwrite() handlers if userspace attempts to access the page(s)
           again.
      
           (Ideally, this would be done in the service handler for CB.CallBack,
           but the server is waiting for our reply before considering, and we
           have a list of vnodes, all of which need breaking - and the process of
           getting the mmap_lock and stripping the PTEs on all CPUs could be
           quite slow.)
      
       (2) Call afs_validate() from the ->map_pages() handler to check to see if
           the file has changed and to get a new callback promise from the
           server.
      
      Also handle the fileserver telling us that it's dropping all callbacks,
      possibly after it's been restarted by sending us a CB.InitCallBackState*
      call by the following means:
      
       (3) Maintain a per-cell list of afs files that are currently mmap'd
           (cell->fs_open_mmaps).
      
       (4) Add a work item to each server that is invoked if there are any open
           mmaps when CB.InitCallBackState happens.  This work item goes through
           the aforementioned list and invokes the vnode->cb_work work item for
           each one that is currently using this server.
      
           This causes the PTEs to be cleared, causing ->map_pages() or
           ->page_mkwrite() to be called again, thereby calling afs_validate()
           again.
      
      I've chosen to simply strip the PTEs at the point of notification reception
      rather than invalidate all the pages as well because (a) it's faster, (b)
      we may get a notification for other reasons than the data being altered (in
      which case we don't want to clobber the pagecache) and (c) we need to ask
      the server to find out - and I don't want to wait for the reply before
      holding up userspace.
      
      This was tested using the attached test program:
      
      	#include <stdbool.h>
      	#include <stdio.h>
      	#include <stdlib.h>
      	#include <unistd.h>
      	#include <fcntl.h>
      	#include <sys/mman.h>
      	int main(int argc, char *argv[])
      	{
      		size_t size = getpagesize();
      		unsigned char *p;
      		bool mod = (argc == 3);
      		int fd;
      		if (argc != 2 && argc != 3) {
      			fprintf(stderr, "Format: %s <file> [mod]\n", argv[0]);
      			exit(2);
      		}
      		fd = open(argv[1], mod ? O_RDWR : O_RDONLY);
      		if (fd < 0) {
      			perror(argv[1]);
      			exit(1);
      		}
      
      		p = mmap(NULL, size, mod ? PROT_READ|PROT_WRITE : PROT_READ,
      			 MAP_SHARED, fd, 0);
      		if (p == MAP_FAILED) {
      			perror("mmap");
      			exit(1);
      		}
      		for (;;) {
      			if (mod) {
      				p[0]++;
      				msync(p, size, MS_ASYNC);
      				fsync(fd);
      			}
      			printf("%02x", p[0]);
      			fflush(stdout);
      			sleep(1);
      		}
      	}
      
      It runs in two modes: in one mode, it mmaps a file, then sits in a loop
      reading the first byte, printing it and sleeping for a second; in the
      second mode it mmaps a file, then sits in a loop incrementing the first
      byte and flushing, then printing and sleeping.
      
      Two instances of this program can be run on different machines, one doing
      the reading and one doing the writing.  The reader should see the changes
      made by the writer, but without this patch, they aren't because validity
      checking is being done lazily - only on entry to the filesystem.
      
      Testing the InitCallBackState change is more complicated.  The server has
      to be taken offline, the saved callback state file removed and then the
      server restarted whilst the reading-mode program continues to run.  The
      client machine then has to poke the server to trigger the InitCallBackState
      call.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Tested-by: NMarkus Suvanto <markus.suvanto@gmail.com>
      cc: linux-afs@lists.infradead.org
      Link: https://lore.kernel.org/r/163111668833.283156.382633263709075739.stgit@warthog.procyon.org.uk/
      6e0e99d5
    • D
      afs: Fix incorrect triggering of sillyrename on 3rd-party invalidation · 63d49d84
      David Howells 提交于
      The AFS filesystem is currently triggering the silly-rename cleanup from
      afs_d_revalidate() when it sees that a dentry has been changed by a third
      party[1].  It should not be doing this as the cleanup includes deleting the
      silly-rename target file on iput.
      
      Fix this by removing the places in the d_revalidate handling that validate
      anything other than the directory and the dirent.  It probably should not
      be looking to validate the target inode of the dentry also.
      
      This includes removing the point in afs_d_revalidate() where the inode that
      a dentry used to point to was marked as being deleted (AFS_VNODE_DELETED).
      We don't know it got deleted.  It could have been renamed or it could have
      hard links remaining.
      
      This was reproduced by cloning a git repo onto an afs volume on one
      machine, switching to another machine and doing "git status", then
      switching back to the first and doing "git status".  The second status
      would show weird output due to ".git/index" getting deleted by the above
      mentioned mechanism.
      
      A simpler way to do it is to do:
      
      	machine 1: touch a
      	machine 2: touch b; mv -f b a
      	machine 1: stat a
      
      on an afs volume.  The bug shows up as the stat failing with ENOENT and the
      file server log showing that machine 1 deleted "a".
      
      Fixes: 79ddbfa5 ("afs: Implement sillyrename for unlink and rename")
      Reported-by: NMarkus Suvanto <markus.suvanto@gmail.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Tested-by: NMarkus Suvanto <markus.suvanto@gmail.com>
      cc: linux-afs@lists.infradead.org
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=214217#c4 [1]
      Link: https://lore.kernel.org/r/163111668100.283156.3851669884664475428.stgit@warthog.procyon.org.uk/
      63d49d84
    • D
      afs: Add missing vnode validation checks · 3978d816
      David Howells 提交于
      afs_d_revalidate() should only be validating the directory entry it is
      given and the directory to which that belongs; it shouldn't be validating
      the inode/vnode to which that dentry points.  Besides, validation need to
      be done even if we don't call afs_d_revalidate() - which might be the case
      if we're starting from a file descriptor.
      
      In order for afs_d_revalidate() to be fixed, validation points must be
      added in some other places.  Certain directory operations, such as
      afs_unlink(), already check this, but not all and not all file operations
      either.
      
      Note that the validation of a vnode not only checks to see if the
      attributes we have are correct, but also gets a promise from the server to
      notify us if that file gets changed by a third party.
      
      Add the following checks:
      
       - Check the vnode we're going to make a hard link to.
       - Check the vnode we're going to move/rename.
       - Check the vnode we're going to read from.
       - Check the vnode we're going to write to.
       - Check the vnode we're going to sync.
       - Check the vnode we're going to make a mapped page writable for.
      
      Some of these aren't strictly necessary as we're going to perform a server
      operation that might get the attributes anyway from which we can determine
      if something changed - though it might not get us a callback promise.
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Tested-by: NMarkus Suvanto <markus.suvanto@gmail.com>
      cc: linux-afs@lists.infradead.org
      Link: https://lore.kernel.org/r/163111667354.283156.12720698333342917516.stgit@warthog.procyon.org.uk/
      3978d816
    • H
      io-wq: fix potential race of acct->nr_workers · 767a65e9
      Hao Xu 提交于
      Given max_worker is 1, and we currently have 1 running and it is
      exiting. There may be race like:
       io_wqe_enqueue                   worker1
                                     no work there and timeout
                                     unlock(wqe->lock)
       ->insert work
                                     -->io_worker_exit
       lock(wqe->lock)
       ->if(!nr_workers) //it's still 1
       unlock(wqe->lock)
          goto run_cancel
                                        lock(wqe->lock)
                                        nr_workers--
                                        ->dec_running
                                          ->worker creation fails
                                        unlock(wqe->lock)
      
      We enqueued one work but there is no workers, causes hung.
      Signed-off-by: NHao Xu <haoxu@linux.alibaba.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      767a65e9
    • H
      io-wq: code clean of io_wqe_create_worker() · 7a842fb5
      Hao Xu 提交于
      Remove do_create to save a local variable.
      Signed-off-by: NHao Xu <haoxu@linux.alibaba.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      7a842fb5
    • J
      io_uring: ensure symmetry in handling iter types in loop_rw_iter() · 16c8d2df
      Jens Axboe 提交于
      When setting up the next segment, we check what type the iter is and
      handle it accordingly. However, when incrementing and processed amount
      we do not, and both iter advance and addr/len are adjusted, regardless
      of type. Split the increment side just like we do on the setup side.
      
      Fixes: 4017eb91 ("io_uring: make loop_rw_iter() use original user supplied pointers")
      Cc: stable@vger.kernel.org
      Reported-by: NValentina Palmiotti <vpalmiotti@gmail.com>
      Reviewed-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      16c8d2df
  7. 11 9月, 2021 3 次提交
  8. 10 9月, 2021 2 次提交
  9. 09 9月, 2021 10 次提交
    • P
      io_uring: fail links of cancelled timeouts · 2ae2eb9d
      Pavel Begunkov 提交于
      When we cancel a timeout we should mark it with REQ_F_FAIL, so
      linked requests are cancelled as well, but not queued for further
      execution.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/fff625b44eeced3a5cae79f60e6acf3fbdf8f990.1631192135.git.asml.silence@gmail.comSigned-off-by: NJens Axboe <axboe@kernel.dk>
      2ae2eb9d
    • Q
      io-wq: fix memory leak in create_io_worker() · 66e70be7
      Qiang.zhang 提交于
      BUG: memory leak
      unreferenced object 0xffff888126fcd6c0 (size 192):
        comm "syz-executor.1", pid 11934, jiffies 4294983026 (age 15.690s)
        backtrace:
          [<ffffffff81632c91>] kmalloc_node include/linux/slab.h:609 [inline]
          [<ffffffff81632c91>] kzalloc_node include/linux/slab.h:732 [inline]
          [<ffffffff81632c91>] create_io_worker+0x41/0x1e0 fs/io-wq.c:739
          [<ffffffff8163311e>] io_wqe_create_worker fs/io-wq.c:267 [inline]
          [<ffffffff8163311e>] io_wqe_enqueue+0x1fe/0x330 fs/io-wq.c:866
          [<ffffffff81620b64>] io_queue_async_work+0xc4/0x200 fs/io_uring.c:1473
          [<ffffffff8162c59c>] __io_queue_sqe+0x34c/0x510 fs/io_uring.c:6933
          [<ffffffff8162c7ab>] io_req_task_submit+0x4b/0xa0 fs/io_uring.c:2233
          [<ffffffff8162cb48>] io_async_task_func+0x108/0x1c0 fs/io_uring.c:5462
          [<ffffffff816259e3>] tctx_task_work+0x1b3/0x3a0 fs/io_uring.c:2158
          [<ffffffff81269b43>] task_work_run+0x73/0xb0 kernel/task_work.c:164
          [<ffffffff812dcdd1>] tracehook_notify_signal include/linux/tracehook.h:212 [inline]
          [<ffffffff812dcdd1>] handle_signal_work kernel/entry/common.c:146 [inline]
          [<ffffffff812dcdd1>] exit_to_user_mode_loop kernel/entry/common.c:172 [inline]
          [<ffffffff812dcdd1>] exit_to_user_mode_prepare+0x151/0x180 kernel/entry/common.c:209
          [<ffffffff843ff25d>] __syscall_exit_to_user_mode_work kernel/entry/common.c:291 [inline]
          [<ffffffff843ff25d>] syscall_exit_to_user_mode+0x1d/0x40 kernel/entry/common.c:302
          [<ffffffff843fa4a2>] do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86
          [<ffffffff84600068>] entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      when create_io_thread() return error, and not retry, the worker object
      need to be freed.
      
      Reported-by: syzbot+65454c239241d3d647da@syzkaller.appspotmail.com
      Signed-off-by: NQiang.zhang <qiang.zhang@windriver.com>
      Link: https://lore.kernel.org/r/20210909115822.181188-1-qiang.zhang@windriver.comSigned-off-by: NJens Axboe <axboe@kernel.dk>
      66e70be7
    • S
      cifs: move SMB FSCTL definitions to common code · 8d014f5f
      Steve French 提交于
      The FSCTL definitions are in smbfsctl.h which should be
      shared by client and server.  Move the updated version of
      smbfsctl.h into smbfs_common and have the client code use
      it (subsequent patch will change the server to use this
      common version of the header).
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      8d014f5f
    • S
      cifs: rename cifs_common to smbfs_common · 23e91d8b
      Steve French 提交于
      As we move to common code between client and server, we have
      been asked to make the names less confusing, and refer less
      to "cifs" and more to words which include "smb" instead to
      e.g. "smbfs" for the client (we already have "ksmbd" for the
      kernel server, and "smbd" for the user space Samba daemon).
      So to be more consistent in the naming of common code between
      client and server and reduce the risk of merge conflicts as
      more common code is added - rename "cifs_common" to
      "smbfs_common" (in future releases we also will rename
      the fs/cifs directory to fs/smbfs)
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      23e91d8b
    • S
      cifs: update FSCTL definitions · fc111fb9
      Steve French 提交于
      Add some missing defines used by ksmbd to the client
      version of smbfsctl.h, and add a missing newer define
      mentioned in the protocol definitions (MS-FSCC).
      
      This will also make it easier to move to common code.
      Reviewed-by: NRonnie Sahlberg <lsahlber@redhat.com>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      fc111fb9
    • J
      io-wq: fix silly logic error in io_task_work_match() · 3b33e3f4
      Jens Axboe 提交于
      We check for the func with an OR condition, which means it always ends
      up being false and we never match the task_work we want to cancel. In
      the unexpected case that we do exit with that pending, we can trigger
      a hang waiting for a worker to exit, but it was never created. syzbot
      reports that as such:
      
      INFO: task syz-executor687:8514 blocked for more than 143 seconds.
            Not tainted 5.14.0-syzkaller #0
      "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      task:syz-executor687 state:D stack:27296 pid: 8514 ppid:  8479 flags:0x00024004
      Call Trace:
       context_switch kernel/sched/core.c:4940 [inline]
       __schedule+0x940/0x26f0 kernel/sched/core.c:6287
       schedule+0xd3/0x270 kernel/sched/core.c:6366
       schedule_timeout+0x1db/0x2a0 kernel/time/timer.c:1857
       do_wait_for_common kernel/sched/completion.c:85 [inline]
       __wait_for_common kernel/sched/completion.c:106 [inline]
       wait_for_common kernel/sched/completion.c:117 [inline]
       wait_for_completion+0x176/0x280 kernel/sched/completion.c:138
       io_wq_exit_workers fs/io-wq.c:1162 [inline]
       io_wq_put_and_exit+0x40c/0xc70 fs/io-wq.c:1197
       io_uring_clean_tctx fs/io_uring.c:9607 [inline]
       io_uring_cancel_generic+0x5fe/0x740 fs/io_uring.c:9687
       io_uring_files_cancel include/linux/io_uring.h:16 [inline]
       do_exit+0x265/0x2a30 kernel/exit.c:780
       do_group_exit+0x125/0x310 kernel/exit.c:922
       get_signal+0x47f/0x2160 kernel/signal.c:2868
       arch_do_signal_or_restart+0x2a9/0x1c40 arch/x86/kernel/signal.c:865
       handle_signal_work kernel/entry/common.c:148 [inline]
       exit_to_user_mode_loop kernel/entry/common.c:172 [inline]
       exit_to_user_mode_prepare+0x17d/0x290 kernel/entry/common.c:209
       __syscall_exit_to_user_mode_work kernel/entry/common.c:291 [inline]
       syscall_exit_to_user_mode+0x19/0x60 kernel/entry/common.c:302
       do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86
       entry_SYSCALL_64_after_hwframe+0x44/0xae
      RIP: 0033:0x445cd9
      RSP: 002b:00007fc657f4b308 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
      RAX: 0000000000000001 RBX: 00000000004cb448 RCX: 0000000000445cd9
      RDX: 00000000000f4240 RSI: 0000000000000081 RDI: 00000000004cb44c
      RBP: 00000000004cb440 R08: 000000000000000e R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 000000000049b154
      R13: 0000000000000003 R14: 00007fc657f4b400 R15: 0000000000022000
      
      While in there, also decrement accr->nr_workers. This isn't strictly
      needed as we're exiting, but let's make sure the accounting matches up.
      
      Fixes: 3146cba9 ("io-wq: make worker creation resilient against signals")
      Reported-by: syzbot+f62d3e0a4ea4f38f5326@syzkaller.appspotmail.com
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      3b33e3f4
    • J
      io_uring: drop ctx->uring_lock before acquiring sqd->lock · 009ad9f0
      Jens Axboe 提交于
      The SQPOLL thread dictates the lock order, and we hold the ctx->uring_lock
      for all the registration opcodes. We also hold a ref to the ctx, and we
      do drop the lock for other reasons to quiesce, so it's fine to drop the
      ctx lock temporarily to grab the sqd->lock. This fixes the following
      lockdep splat:
      
      ======================================================
      WARNING: possible circular locking dependency detected
      5.14.0-syzkaller #0 Not tainted
      ------------------------------------------------------
      syz-executor.5/25433 is trying to acquire lock:
      ffff888023426870 (&sqd->lock){+.+.}-{3:3}, at: io_register_iowq_max_workers fs/io_uring.c:10551 [inline]
      ffff888023426870 (&sqd->lock){+.+.}-{3:3}, at: __io_uring_register fs/io_uring.c:10757 [inline]
      ffff888023426870 (&sqd->lock){+.+.}-{3:3}, at: __do_sys_io_uring_register+0x10aa/0x2e70 fs/io_uring.c:10792
      
      but task is already holding lock:
      ffff8880885b40a8 (&ctx->uring_lock){+.+.}-{3:3}, at: __do_sys_io_uring_register+0x2e1/0x2e70 fs/io_uring.c:10791
      
      which lock already depends on the new lock.
      
      the existing dependency chain (in reverse order) is:
      
      -> #1 (&ctx->uring_lock){+.+.}-{3:3}:
             __mutex_lock_common kernel/locking/mutex.c:596 [inline]
             __mutex_lock+0x131/0x12f0 kernel/locking/mutex.c:729
             __io_sq_thread fs/io_uring.c:7291 [inline]
             io_sq_thread+0x65a/0x1370 fs/io_uring.c:7368
             ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295
      
      -> #0 (&sqd->lock){+.+.}-{3:3}:
             check_prev_add kernel/locking/lockdep.c:3051 [inline]
             check_prevs_add kernel/locking/lockdep.c:3174 [inline]
             validate_chain kernel/locking/lockdep.c:3789 [inline]
             __lock_acquire+0x2a07/0x54a0 kernel/locking/lockdep.c:5015
             lock_acquire kernel/locking/lockdep.c:5625 [inline]
             lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5590
             __mutex_lock_common kernel/locking/mutex.c:596 [inline]
             __mutex_lock+0x131/0x12f0 kernel/locking/mutex.c:729
             io_register_iowq_max_workers fs/io_uring.c:10551 [inline]
             __io_uring_register fs/io_uring.c:10757 [inline]
             __do_sys_io_uring_register+0x10aa/0x2e70 fs/io_uring.c:10792
             do_syscall_x64 arch/x86/entry/common.c:50 [inline]
             do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
             entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      other info that might help us debug this:
      
       Possible unsafe locking scenario:
      
             CPU0                    CPU1
             ----                    ----
        lock(&ctx->uring_lock);
                                     lock(&sqd->lock);
                                     lock(&ctx->uring_lock);
        lock(&sqd->lock);
      
       *** DEADLOCK ***
      
      Fixes: 2e480058 ("io-wq: provide a way to limit max number of workers")
      Reported-by: syzbot+97fa56483f69d677969f@syzkaller.appspotmail.com
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      009ad9f0
    • N
      ksmbd: fix control flow issues in sid_to_id() · 4cf0ccd0
      Namjae Jeon 提交于
      Addresses-Coverity reported Control flow issues in sid_to_id()
      /fs/ksmbd/smbacl.c: 277 in sid_to_id()
      271
      272	if (sidtype == SIDOWNER) {
      273		kuid_t uid;
      274		uid_t id;
      275
      276		id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]);
      >>>	CID 1506810:  Control flow issues  (NO_EFFECT)
      >>>	This greater-than-or-equal-to-zero comparison of an unsigned value
      >>>	is always true. "id >= 0U".
      277		if (id >= 0) {
      278			/*
      279			 * Translate raw sid into kuid in the server's user
      280			 * namespace.
      281			 */
      282			uid = make_kuid(&init_user_ns, id);
      
      Addresses-Coverity: ("Control flow issues")
      Signed-off-by: NNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      4cf0ccd0
    • N
      ksmbd: fix read of uninitialized variable ret in set_file_basic_info · 4ffd5264
      Namjae Jeon 提交于
      Addresses-Coverity reported Uninitialized variables warninig :
      
      /fs/ksmbd/smb2pdu.c: 5525 in set_file_basic_info()
      5519                    if (!rc) {
      5520                            inode->i_ctime = ctime;
      5521                            mark_inode_dirty(inode);
      5522                    }
      5523                    inode_unlock(inode);
      5524            }
      >>>     CID 1506805:  Uninitialized variables  (UNINIT)
      >>>     Using uninitialized value "rc".
      5525            return rc;
      5526     }
      5527
      5528     static int set_file_allocation_info(struct ksmbd_work *work,
      5529                                 struct ksmbd_file *fp, char *buf)
      5530     {
      
      Addresses-Coverity: ("Uninitialized variable")
      Signed-off-by: NNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      4ffd5264
    • C
      ksmbd: add missing assignments to ret on ndr_read_int64 read calls · 36bbeb33
      Colin Ian King 提交于
      Currently there are two ndr_read_int64 calls where ret is being checked
      for failure but ret is not being assigned a return value from the call.
      Static analyis is reporting the checks on ret as dead code.  Fix this.
      
      Addresses-Coverity: ("Logical dead code")
      Reviewed-by: NSergey Senozhatsky <senozhatsky@chromium.org>
      Signed-off-by: NColin Ian King <colin.king@canonical.com>
      Signed-off-by: NNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: NSteve French <stfrench@microsoft.com>
      36bbeb33