Skip to content
  1. Jan 16, 2024
  2. Jan 05, 2024
    • Greg Kroah-Hartman's avatar
    • Jiri Olsa's avatar
      bpf: Fix prog_array_map_poke_run map poke update · 13578b4e
      Jiri Olsa authored
      commit 4b7de801 upstream.
      
      Lee pointed out issue found by syscaller [0] hitting BUG in prog array
      map poke update in prog_array_map_poke_run function due to error value
      returned from bpf_arch_text_poke function.
      
      There's race window where bpf_arch_text_poke can fail due to missing
      bpf program kallsym symbols, which is accounted for with check for
      -EINVAL in that BUG_ON call.
      
      The problem is that in such case we won't update the tail call jump
      and cause imbalance for the next tail call update check which will
      fail with -EBUSY in bpf_arch_text_poke.
      
      I'm hitting following race during the program load:
      
        CPU 0                             CPU 1
      
        bpf_prog_load
          bpf_check
            do_misc_fixups
              prog_array_map_poke_track
      
                                          map_update_elem
                                            bpf_fd_array_map_update_elem
                                              prog_array_map_poke_run
      
                                                bpf_arch_text_poke returns -EINVAL
      
          bpf_prog_kallsyms_add
      
      After bpf_arch_text_poke (CPU 1) fails to update the tail call jump, the next
      poke update fails on expected jump instruction check in bpf_arch_text_poke
      with -EBUSY and triggers the BUG_ON in prog_array_map_poke_run.
      
      Similar race exists on the program unload.
      
      Fixing this by moving the update to bpf_arch_poke_desc_update function which
      makes sure we call __bpf_arch_text_poke that skips the bpf address check.
      
      Each architecture has slightly different approach wrt looking up bpf address
      in bpf_arch_text_poke, so instead of splitting the function or adding new
      'checkip' argument in previous version, it seems best to move the whole
      map_poke_run update as arch specific code.
      
        [0] https://syzkaller.appspot.com/bug?extid=97a4fe20470e9bc30810
      
      Fixes: ebf7d1f5
      
       ("bpf, x64: rework pro/epilogue and tailcall handling in JIT")
      Reported-by: default avatar <syzbot+97a4fe20470e9bc30810@syzkaller.appspotmail.com>
      Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Cc: Lee Jones <lee@kernel.org>
      Cc: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
      Link: https://lore.kernel.org/bpf/20231206083041.1306660-2-jolsa@kernel.org
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      13578b4e
    • Andy Shevchenko's avatar
      device property: Allow const parameter to dev_fwnode() · 339add04
      Andy Shevchenko authored
      commit b295d484
      
       upstream.
      
      It's not fully correct to take a const parameter pointer to a struct
      and return a non-const pointer to a member of that struct.
      
      Instead, introduce a const version of the dev_fwnode() API which takes
      and returns const pointers and use it where it's applicable.
      
      With this, convert dev_fwnode() to be a macro wrapper on top of const
      and non-const APIs that chooses one based on the type.
      
      Suggested-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Fixes: aade55c8
      
       ("device property: Add const qualifier to device_get_match_data() parameter")
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Acked-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Reviewed-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
      Link: https://lore.kernel.org/r/20221004092129.19412-2-andriy.shevchenko@linux.intel.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      339add04
    • Mikulas Patocka's avatar
      dm-integrity: don't modify bio's immutable bio_vec in integrity_metadata() · 4d9dcdb3
      Mikulas Patocka authored
      commit b86f4b79 upstream.
      
      __bio_for_each_segment assumes that the first struct bio_vec argument
      doesn't change - it calls "bio_advance_iter_single((bio), &(iter),
      (bvl).bv_len)" to advance the iterator. Unfortunately, the dm-integrity
      code changes the bio_vec with "bv.bv_len -= pos". When this code path
      is taken, the iterator would be out of sync and dm-integrity would
      report errors. This happens if the machine is out of memory and
      "kmalloc" fails.
      
      Fix this bug by making a copy of "bv" and changing the copy instead.
      
      Fixes: 7eada909
      
       ("dm: add integrity target")
      Cc: stable@vger.kernel.org	# v4.12+
      Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
      Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4d9dcdb3
    • Steven Rostedt (Google)'s avatar
      ring-buffer: Fix slowpath of interrupted event · a033bb82
      Steven Rostedt (Google) authored
      commit b803d7c6 upstream.
      
      To synchronize the timestamps with the ring buffer reservation, there are
      two timestamps that are saved in the buffer meta data.
      
      1. before_stamp
      2. write_stamp
      
      When the two are equal, the write_stamp is considered valid, as in, it may
      be used to calculate the delta of the next event as the write_stamp is the
      timestamp of the previous reserved event on the buffer.
      
      This is done by the following:
      
       /*A*/	w = current position on the ring buffer
      	before = before_stamp
      	after = write_stamp
      	ts = read current timestamp
      
      	if (before != after) {
      		write_stamp is not valid, force adding an absolute
      		timestamp.
      	}
      
       /*B*/	before_stamp = ts
      
       /*C*/	write = local_add_return(event length, position on ring buffer)
      
      	if (w == write - event length) {
      		/* Nothing interrupted between A and C */
       /*E*/		write_stamp = ts;
      		delta = ts - after
      		/*
      		 * If nothing interrupted again,
      		 * before_stamp == write_stamp and write_stamp
      		 * can be used to calculate the delta for
      		 * events that come in after this one.
      		 */
      	} else {
      
      		/*
      		 * The slow path!
      		 * Was interrupted between A and C.
      		 */
      
      This is the place that there's a bug. We currently have:
      
      		after = write_stamp
      		ts = read current timestamp
      
       /*F*/		if (write == current position on the ring buffer &&
      		    after < ts && cmpxchg(write_stamp, after, ts)) {
      
      			delta = ts - after;
      
      		} else {
      			delta = 0;
      		}
      
      The assumption is that if the current position on the ring buffer hasn't
      moved between C and F, then it also was not interrupted, and that the last
      event written has a timestamp that matches the write_stamp. That is the
      write_stamp is valid.
      
      But this may not be the case:
      
      If a task context event was interrupted by softirq between B and C.
      
      And the softirq wrote an event that got interrupted by a hard irq between
      C and E.
      
      and the hard irq wrote an event (does not need to be interrupted)
      
      We have:
      
       /*B*/ before_stamp = ts of normal context
      
         ---> interrupted by softirq
      
      	/*B*/ before_stamp = ts of softirq context
      
      	  ---> interrupted by hardirq
      
      		/*B*/ before_stamp = ts of hard irq context
      		/*E*/ write_stamp = ts of hard irq context
      
      		/* matches and write_stamp valid */
      	  <----
      
      	/*E*/ write_stamp = ts of softirq context
      
      	/* No longer matches before_stamp, write_stamp is not valid! */
      
         <---
      
       w != write - length, go to slow path
      
      // Right now the order of events in the ring buffer is:
      //
      // |-- softirq event --|-- hard irq event --|-- normal context event --|
      //
      
       after = write_stamp (this is the ts of softirq)
       ts = read current timestamp
      
       if (write == current position on the ring buffer [true] &&
           after < ts [true] && cmpxchg(write_stamp, after, ts) [true]) {
      
      	delta = ts - after  [Wrong!]
      
      The delta is to be between the hard irq event and the normal context
      event, but the above logic made the delta between the softirq event and
      the normal context event, where the hard irq event is between the two. This
      will shift all the remaining event timestamps on the sub-buffer
      incorrectly.
      
      The write_stamp is only valid if it matches the before_stamp. The cmpxchg
      does nothing to help this.
      
      Instead, the following logic can be done to fix this:
      
      	before = before_stamp
      	ts = read current timestamp
      	before_stamp = ts
      
      	after = write_stamp
      
      	if (write == current position on the ring buffer &&
      	    after == before && after < ts) {
      
      		delta = ts - after
      
      	} else {
      		delta = 0;
      	}
      
      The above will only use the write_stamp if it still matches before_stamp
      and was tested to not have changed since C.
      
      As a bonus, with this logic we do not need any 64-bit cmpxchg() at all!
      
      This means the 32-bit rb_time_t workaround can finally be removed. But
      that's for a later time.
      
      Link: https://lore.kernel.org/linux-trace-kernel/20231218175229.58ec3daf@gandalf.local.home/
      Link: https://lore.kernel.org/linux-trace-kernel/20231218230712.3a76b081@gandalf.local.home
      
      Cc: stable@vger.kernel.org
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Fixes: dd939425
      
       ("ring-buffer: Do not try to put back write_stamp")
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a033bb82
    • Pablo Neira Ayuso's avatar
      netfilter: nf_tables: skip set commit for deleted/destroyed sets · d10f7540
      Pablo Neira Ayuso authored
      commit 7315dc1e upstream.
      
      NFT_MSG_DELSET deactivates all elements in the set, skip
      set->ops->commit() to avoid the unnecessary clone (for the pipapo case)
      as well as the sync GC cycle, which could deactivate again expired
      elements in such set.
      
      Fixes: 5f68718b
      
       ("netfilter: nf_tables: GC transaction API to avoid race with control plane")
      Reported-by: default avatarKevin Rich <kevinrich1337@gmail.com>
      Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d10f7540
    • Namjae Jeon's avatar
      ksmbd: fix slab-out-of-bounds in smb_strndup_from_utf16() · d739f2b6
      Namjae Jeon authored
      commit d10c7787
      
       upstream.
      
      If ->NameOffset/Length is bigger than ->CreateContextsOffset/Length,
      ksmbd_check_message doesn't validate request buffer it correctly.
      So slab-out-of-bounds warning from calling smb_strndup_from_utf16()
      in smb2_open() could happen. If ->NameLength is non-zero, Set the larger
      of the two sums (Name and CreateContext size) as the offset and length of
      the data area.
      
      Reported-by: default avatarYang Chaoming <lometsj@live.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d739f2b6
    • Steven Rostedt (Google)'s avatar
      ring-buffer: Remove useless update to write_stamp in rb_try_to_discard() · 53bed9b9
      Steven Rostedt (Google) authored
      commit 083e9f65 upstream.
      
      When filtering is enabled, a temporary buffer is created to place the
      content of the trace event output so that the filter logic can decide
      from the trace event output if the trace event should be filtered out or
      not. If it is to be filtered out, the content in the temporary buffer is
      simply discarded, otherwise it is written into the trace buffer.
      
      But if an interrupt were to come in while a previous event was using that
      temporary buffer, the event written by the interrupt would actually go
      into the ring buffer itself to prevent corrupting the data on the
      temporary buffer. If the event is to be filtered out, the event in the
      ring buffer is discarded, or if it fails to discard because another event
      were to have already come in, it is turned into padding.
      
      The update to the write_stamp in the rb_try_to_discard() happens after a
      fix was made to force the next event after the discard to use an absolute
      timestamp by setting the before_stamp to zero so it does not match the
      write_stamp (which causes an event to use the absolute timestamp).
      
      But there's an effort in rb_try_to_discard() to put back the write_stamp
      to what it was before the event was added. But this is useless and
      wasteful because nothing is going to be using that write_stamp for
      calculations as it still will not match the before_stamp.
      
      Remove this useless update, and in doing so, we remove another
      cmpxchg64()!
      
      Also update the comments to reflect this change as well as remove some
      extra white space in another comment.
      
      Link: https://lore.kernel.org/linux-trace-kernel/20231215081810.1f4f38fe@rorschach.local.home
      
      Cc: Masami Hiramatsu <mhiramat@kernel.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Joel Fernandes <joel@joelfernandes.org>
      Cc: Vincent Donnefort   <vdonnefort@google.com>
      Fixes: b2dd7975
      
       ("ring-buffer: Force absolute timestamp on discard of event")
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      53bed9b9
    • Steven Rostedt (Google)'s avatar
      tracing: Fix blocked reader of snapshot buffer · 7fb264ae
      Steven Rostedt (Google) authored
      commit 39a7dc23 upstream.
      
      If an application blocks on the snapshot or snapshot_raw files, expecting
      to be woken up when a snapshot occurs, it will not happen. Or it may
      happen with an unexpected result.
      
      That result is that the application will be reading the main buffer
      instead of the snapshot buffer. That is because when the snapshot occurs,
      the main and snapshot buffers are swapped. But the reader has a descriptor
      still pointing to the buffer that it originally connected to.
      
      This is fine for the main buffer readers, as they may be blocked waiting
      for a watermark to be hit, and when a snapshot occurs, the data that the
      main readers want is now on the snapshot buffer.
      
      But for waiters of the snapshot buffer, they are waiting for an event to
      occur that will trigger the snapshot and they can then consume it quickly
      to save the snapshot before the next snapshot occurs. But to do this, they
      need to read the new snapshot buffer, not the old one that is now
      receiving new data.
      
      Also, it does not make sense to have a watermark "buffer_percent" on the
      snapshot buffer, as the snapshot buffer is static and does not receive new
      data except all at once.
      
      Link: https://lore.kernel.org/linux-trace-kernel/20231228095149.77f5b45d@gandalf.local.home
      
      
      
      Cc: stable@vger.kernel.org
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Fixes: debdd57f
      
       ("tracing: Make a snapshot feature available from userspace")
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7fb264ae
    • Steven Rostedt (Google)'s avatar
      ring-buffer: Fix wake ups when buffer_percent is set to 100 · c73cb01a
      Steven Rostedt (Google) authored
      commit 623b1f89 upstream.
      
      The tracefs file "buffer_percent" is to allow user space to set a
      water-mark on how much of the tracing ring buffer needs to be filled in
      order to wake up a blocked reader.
      
       0 - is to wait until any data is in the buffer
       1 - is to wait for 1% of the sub buffers to be filled
       50 - would be half of the sub buffers are filled with data
       100 - is not to wake the waiter until the ring buffer is completely full
      
      Unfortunately the test for being full was:
      
      	dirty = ring_buffer_nr_dirty_pages(buffer, cpu);
      	return (dirty * 100) > (full * nr_pages);
      
      Where "full" is the value for "buffer_percent".
      
      There is two issues with the above when full == 100.
      
      1. dirty * 100 > 100 * nr_pages will never be true
         That is, the above is basically saying that if the user sets
         buffer_percent to 100, more pages need to be dirty than exist in the
         ring buffer!
      
      2. The page that the writer is on is never considered dirty, as dirty
         pages are only those that are full. When the writer goes to a new
         sub-buffer, it clears the contents of that sub-buffer.
      
      That is, even if the check was ">=" it would still not be equal as the
      most pages that can be considered "dirty" is nr_pages - 1.
      
      To fix this, add one to dirty and use ">=" in the compare.
      
      Link: https://lore.kernel.org/linux-trace-kernel/20231226125902.4a057f1d@gandalf.local.home
      
      
      
      Cc: stable@vger.kernel.org
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Fixes: 03329f99
      
       ("tracing: Add tracefs file buffer_percentage")
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c73cb01a
    • Baokun Li's avatar
      mm/filemap: avoid buffered read/write race to read inconsistent data · c0be5218
      Baokun Li authored
      commit e2c27b80 upstream.
      
      The following concurrency may cause the data read to be inconsistent with
      the data on disk:
      
                   cpu1                           cpu2
      ------------------------------|------------------------------
                                     // Buffered write 2048 from 0
                                     ext4_buffered_write_iter
                                      generic_perform_write
                                       copy_page_from_iter_atomic
                                       ext4_da_write_end
                                        ext4_da_do_write_end
                                         block_write_end
                                          __block_commit_write
                                           folio_mark_uptodate
      // Buffered read 4096 from 0          smp_wmb()
      ext4_file_read_iter                   set_bit(PG_uptodate, folio_flags)
       generic_file_read_iter            i_size_write // 2048
        filemap_read                     unlock_page(page)
         filemap_get_pages
          filemap_get_read_batch
          folio_test_uptodate(folio)
           ret = test_bit(PG_uptodate, folio_flags)
           if (ret)
            smp_rmb();
            // Ensure that the data in page 0-2048 is up-to-date.
      
                                     // New buffered write 2048 from 2048
                                     ext4_buffered_write_iter
                                      generic_perform_write
                                       copy_page_from_iter_atomic
                                       ext4_da_write_end
                                        ext4_da_do_write_end
                                         block_write_end
                                          __block_commit_write
                                           folio_mark_uptodate
                                            smp_wmb()
                                            set_bit(PG_uptodate, folio_flags)
                                         i_size_write // 4096
                                         unlock_page(page)
      
         isize = i_size_read(inode) // 4096
         // Read the latest isize 4096, but without smp_rmb(), there may be
         // Load-Load disorder resulting in the data in the 2048-4096 range
         // in the page is not up-to-date.
         copy_page_to_iter
         // copyout 4096
      
      In the concurrency above, we read the updated i_size, but there is no read
      barrier to ensure that the data in the page is the same as the i_size at
      this point, so we may copy the unsynchronized page out.  Hence adding the
      missing read memory barrier to fix this.
      
      This is a Load-Load reordering issue, which only occurs on some weak
      mem-ordering architectures (e.g.  ARM64, ALPHA), but not on strong
      mem-ordering architectures (e.g.  X86).  And theoretically the problem
      doesn't only happen on ext4, filesystems that call filemap_read() but
      don't hold inode lock (e.g.  btrfs, f2fs, ubifs ...) will have this
      problem, while filesystems with inode lock (e.g.  xfs, nfs) won't have
      this problem.
      
      Link: https://lkml.kernel.org/r/20231213062324.739009-1-libaokun1@huawei.com
      
      
      Signed-off-by: default avatarBaokun Li <libaokun1@huawei.com>
      Reviewed-by: default avatarJan Kara <jack@suse.cz>
      Cc: Andreas Dilger <adilger.kernel@dilger.ca>
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Dave Chinner <david@fromorbit.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
      Cc: Theodore Ts'o <tytso@mit.edu>
      Cc: yangerkun <yangerkun@huawei.com>
      Cc: Yu Kuai <yukuai3@huawei.com>
      Cc: Zhang Yi <yi.zhang@huawei.com>
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c0be5218
    • Hyunwoo Kim's avatar
      Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg · 2b16d960
      Hyunwoo Kim authored
      [ Upstream commit 2e07e834 ]
      
      This can cause a race with bt_sock_ioctl() because
      bt_sock_recvmsg() gets the skb from sk->sk_receive_queue
      and then frees it without holding lock_sock.
      A use-after-free for a skb occurs with the following flow.
      ```
      bt_sock_recvmsg() -> skb_recv_datagram() -> skb_free_datagram()
      bt_sock_ioctl() -> skb_peek()
      ```
      Add lock_sock to bt_sock_recvmsg() to fix this issue.
      
      Cc: stable@vger.kernel.org
      Fixes: 1da177e4
      
       ("Linux-2.6.12-rc2")
      Signed-off-by: default avatarHyunwoo Kim <v4bel@theori.io>
      Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2b16d960
    • Paulo Alcantara's avatar
      smb: client: fix OOB in smbCalcSize() · ded3cfde
      Paulo Alcantara authored
      [ Upstream commit b35858b3
      
       ]
      
      Validate @smb->WordCount to avoid reading off the end of @smb and thus
      causing the following KASAN splat:
      
        BUG: KASAN: slab-out-of-bounds in smbCalcSize+0x32/0x40 [cifs]
        Read of size 2 at addr ffff88801c024ec5 by task cifsd/1328
      
        CPU: 1 PID: 1328 Comm: cifsd Not tainted 6.7.0-rc5 #9
        Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS
        rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014
        Call Trace:
         <TASK>
         dump_stack_lvl+0x4a/0x80
         print_report+0xcf/0x650
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? __phys_addr+0x46/0x90
         kasan_report+0xd8/0x110
         ? smbCalcSize+0x32/0x40 [cifs]
         ? smbCalcSize+0x32/0x40 [cifs]
         kasan_check_range+0x105/0x1b0
         smbCalcSize+0x32/0x40 [cifs]
         checkSMB+0x162/0x370 [cifs]
         ? __pfx_checkSMB+0x10/0x10 [cifs]
         cifs_handle_standard+0xbc/0x2f0 [cifs]
         ? srso_alias_return_thunk+0x5/0xfbef5
         cifs_demultiplex_thread+0xed1/0x1360 [cifs]
         ? __pfx_cifs_demultiplex_thread+0x10/0x10 [cifs]
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? lockdep_hardirqs_on_prepare+0x136/0x210
         ? __pfx_lock_release+0x10/0x10
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? mark_held_locks+0x1a/0x90
         ? lockdep_hardirqs_on_prepare+0x136/0x210
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? __kthread_parkme+0xce/0xf0
         ? __pfx_cifs_demultiplex_thread+0x10/0x10 [cifs]
         kthread+0x18d/0x1d0
         ? kthread+0xdb/0x1d0
         ? __pfx_kthread+0x10/0x10
         ret_from_fork+0x34/0x60
         ? __pfx_kthread+0x10/0x10
         ret_from_fork_asm+0x1b/0x30
         </TASK>
      
      This fixes CVE-2023-6606.
      
      Reported-by: default avatar <j51569436@gmail.com>
      Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218218
      
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaulo Alcantara (SUSE) <pc@manguebit.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      ded3cfde
    • Paulo Alcantara's avatar
      smb: client: fix OOB in SMB2_query_info_init() · bfd18c0f
      Paulo Alcantara authored
      [ Upstream commit 33eae65c ]
      
      A small CIFS buffer (448 bytes) isn't big enough to hold
      SMB2_QUERY_INFO request along with user's input data from
      CIFS_QUERY_INFO ioctl.  That is, if the user passed an input buffer >
      344 bytes, the client will memcpy() off the end of @req->Buffer in
      SMB2_query_info_init() thus causing the following KASAN splat:
      
        BUG: KASAN: slab-out-of-bounds in SMB2_query_info_init+0x242/0x250 [cifs]
        Write of size 1023 at addr ffff88801308c5a8 by task a.out/1240
      
        CPU: 1 PID: 1240 Comm: a.out Not tainted 6.7.0-rc4 #5
        Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS
        rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014
        Call Trace:
         <TASK>
         dump_stack_lvl+0x4a/0x80
         print_report+0xcf/0x650
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? __phys_addr+0x46/0x90
         kasan_report+0xd8/0x110
         ? SMB2_query_info_init+0x242/0x250 [cifs]
         ? SMB2_query_info_init+0x242/0x250 [cifs]
         kasan_check_range+0x105/0x1b0
         __asan_memcpy+0x3c/0x60
         SMB2_query_info_init+0x242/0x250 [cifs]
         ? __pfx_SMB2_query_info_init+0x10/0x10 [cifs]
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? smb_rqst_len+0xa6/0xc0 [cifs]
         smb2_ioctl_query_info+0x4f4/0x9a0 [cifs]
         ? __pfx_smb2_ioctl_query_info+0x10/0x10 [cifs]
         ? __pfx_cifsConvertToUTF16+0x10/0x10 [cifs]
         ? kasan_set_track+0x25/0x30
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? __kasan_kmalloc+0x8f/0xa0
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? cifs_strndup_to_utf16+0x12d/0x1a0 [cifs]
         ? __build_path_from_dentry_optional_prefix+0x19d/0x2d0 [cifs]
         ? __pfx_smb2_ioctl_query_info+0x10/0x10 [cifs]
         cifs_ioctl+0x11c7/0x1de0 [cifs]
         ? __pfx_cifs_ioctl+0x10/0x10 [cifs]
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? rcu_is_watching+0x23/0x50
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? __rseq_handle_notify_resume+0x6cd/0x850
         ? __pfx___schedule+0x10/0x10
         ? blkcg_iostat_update+0x250/0x290
         ? srso_alias_return_thunk+0x5/0xfbef5
         ? ksys_write+0xe9/0x170
         __x64_sys_ioctl+0xc9/0x100
         do_syscall_64+0x47/0xf0
         entry_SYSCALL_64_after_hwframe+0x6f/0x77
        RIP: 0033:0x7f893dde49cf
        Code: 00 48 89 44 24 18 31 c0 48 8d 44 24 60 c7 04 24 10 00 00 00 48
        89 44 24 08 48 8d 44 24 20 48 89 44 24 10 b8 10 00 00 00 0f 05 <89>
        c2 3d 00 f0 ff ff 77 18 48 8b 44 24 18 64 48 2b 04 25 28 00 00
        RSP: 002b:00007ffc03ff4160 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
        RAX: ffffffffffffffda RBX: 00007ffc03ff4378 RCX: 00007f893dde49cf
        RDX: 00007ffc03ff41d0 RSI: 00000000c018cf07 RDI: 0000000000000003
        RBP: 00007ffc03ff4260 R08: 0000000000000410 R09: 0000000000000001
        R10: 00007f893dce7300 R11: 0000000000000246 R12: 0000000000000000
        R13: 00007ffc03ff4388 R14: 00007f893df15000 R15: 0000000000406de0
         </TASK>
      
      Fix this by increasing size of SMB2_QUERY_INFO request buffers and
      validating input length to prevent other callers from overflowing @req
      in SMB2_query_info_init() as well.
      
      Fixes: f5b05d62
      
       ("cifs: add IOCTL for QUERY_INFO passthrough to userspace")
      Cc: stable@vger.kernel.org
      Reported-by: default avatarRobert Morris <rtm@csail.mit.edu>
      Signed-off-by: default avatarPaulo Alcantara <pc@manguebit.com>
      Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bfd18c0f
    • Nuno Sa's avatar
      iio: imu: adis16475: add spi_device_id table · 1228354a
      Nuno Sa authored
      [ Upstream commit ee4d7905 ]
      
      This prevents the warning message "SPI driver has no spi_device_id for..."
      when registering the driver. More importantly, it makes sure that
      module autoloading works as spi relies on spi: modaliases and not of.
      
      While at it, move the of_device_id table to it's natural place.
      
      Fixes: fff7352b
      
       ("iio: imu: Add support for adis16475")
      Signed-off-by: default avatarNuno Sa <nuno.sa@analog.com>
      Link: https://lore.kernel.org/r/20231102125258.3284830-1-nuno.sa@analog.com
      
      
      Cc: <Stable@vger.kernel.org>
      Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      1228354a
    • Andy Shevchenko's avatar
      spi: Introduce spi_get_device_match_data() helper · bd1be85d
      Andy Shevchenko authored
      [ Upstream commit aea672d0
      
       ]
      
      The proposed spi_get_device_match_data() helper is for retrieving
      a driver data associated with the ID in an ID table. First, it tries
      to get driver data of the device enumerated by firmware interface
      (usually Device Tree or ACPI). If none is found it falls back to
      the SPI ID table matching.
      
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Link: https://lore.kernel.org/r/20221020195421.10482-1-andriy.shevchenko@linux.intel.com
      
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Stable-dep-of: ee4d7905
      
       ("iio: imu: adis16475: add spi_device_id table")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      bd1be85d
    • Andy Shevchenko's avatar
      device property: Add const qualifier to device_get_match_data() parameter · fcf6fce2
      Andy Shevchenko authored
      [ Upstream commit aade55c8
      
       ]
      
      Add const qualifier to the device_get_match_data() parameter.
      Some of the future users may utilize this function without
      forcing the type.
      
      All the same, dev_fwnode() may be used with a const qualifier.
      
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Acked-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
      Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Link: https://lore.kernel.org/r/20220922135410.49694-1-andriy.shevchenko@linux.intel.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      fcf6fce2
    • Jose Ignacio Tornos Martinez's avatar
      net: usb: ax88179_178a: avoid failed operations when device is disconnected · d63fafd6
      Jose Ignacio Tornos Martinez authored
      [ Upstream commit aef05e34 ]
      
      When the device is disconnected we get the following messages showing
      failed operations:
      Nov 28 20:22:11 localhost kernel: usb 2-3: USB disconnect, device number 2
      Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3: unregister 'ax88179_178a' usb-0000:02:00.0-3, ASIX AX88179 USB 3.0 Gigabit Ethernet
      Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3: Failed to read reg index 0x0002: -19
      Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3: Failed to write reg index 0x0002: -19
      Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3 (unregistered): Failed to write reg index 0x0002: -19
      Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3 (unregistered): Failed to write reg index 0x0001: -19
      Nov 28 20:22:11 localhost kernel: ax88179_178a 2-3:1.0 enp2s0u3 (unregistered): Failed to write reg index 0x0002: -19
      
      The reason is that although the device is detached, normal stop and
      unbind operations are commanded from the driver. These operations are
      not necessary in this situation, so avoid these logs when the device is
      detached if the result of the operation is -ENODEV and if the new flag
      informing about the disconnecting status is enabled.
      
      cc:  <stable@vger.kernel.org>
      Fixes: e2ca90c2
      
       ("ax88179_178a: ASIX AX88179_178A USB 3.0/2.0 to gigabit ethernet adapter driver")
      Signed-off-by: default avatarJose Ignacio Tornos Martinez <jtornosm@redhat.com>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Link: https://lore.kernel.org/r/20231207175007.263907-1-jtornosm@redhat.com
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d63fafd6
    • Justin Chen's avatar
      net: usb: ax88179_178a: wol optimizations · f860413a
      Justin Chen authored
      [ Upstream commit 50505316
      
       ]
      
      - Check if wol is supported on reset instead of everytime get_wol
      is called.
      - Save wolopts in private data instead of relying on the HW to save it.
      - Defer enabling WoL until suspend instead of enabling it everytime
      set_wol is called.
      
      Signed-off-by: default avatarJustin Chen <justinpopo6@gmail.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Stable-dep-of: aef05e34
      
       ("net: usb: ax88179_178a: avoid failed operations when device is disconnected")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      f860413a
    • Justin Chen's avatar
      net: usb: ax88179_178a: clean up pm calls · 2964a0de
      Justin Chen authored
      [ Upstream commit 843f9205
      
       ]
      
      Instead of passing in_pm flags all over the place, use the private
      struct to handle in_pm mode.
      
      Signed-off-by: default avatarJustin Chen <justinpopo6@gmail.com>
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Stable-dep-of: aef05e34
      
       ("net: usb: ax88179_178a: avoid failed operations when device is disconnected")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      2964a0de
    • Jakub Kicinski's avatar
      ethernet: constify references to netdev->dev_addr in drivers · 597305fd
      Jakub Kicinski authored
      [ Upstream commit 76660757 ]
      
      This big patch sprinkles const on local variables and
      function arguments which may refer to netdev->dev_addr.
      
      Commit 406f42fa ("net-next: When a bond have a massive amount
      of VLANs...") introduced a rbtree for faster Ethernet address look
      up. To maintain netdev->dev_addr in this tree we need to make all
      the writes to it got through appropriate helpers.
      
      Some of the changes here are not strictly required - const
      is sometimes cast off but pointer is not used for writing.
      It seems like it's still better to add the const in case
      the code changes later or relevant -W flags get enabled
      for the build.
      
      No functional changes.
      
      Link: https://lore.kernel.org/r/20211014142432.449314-1-kuba@kernel.org
      
      
      Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      Stable-dep-of: aef05e34
      
       ("net: usb: ax88179_178a: avoid failed operations when device is disconnected")
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      597305fd
    • Dan Carpenter's avatar
      usb: fotg210-hcd: delete an incorrect bounds test · 32d9a4ce
      Dan Carpenter authored
      [ Upstream commit 7fbcd195 ]
      
      Here "temp" is the number of characters that we have written and "size"
      is the size of the buffer.  The intent was clearly to say that if we have
      written to the end of the buffer then stop.
      
      However, for that to work the comparison should have been done on the
      original "size" value instead of the "size -= temp" value.  Not only
      will that not trigger when we want to, but there is a small chance that
      it will trigger incorrectly before we want it to and we break from the
      loop slightly earlier than intended.
      
      This code was recently changed from using snprintf() to scnprintf().  With
      snprintf() we likely would have continued looping and passed a negative
      size parameter to snprintf().  This would have triggered an annoying
      WARN().  Now that we have converted to scnprintf() "size" will never
      drop below 1 and there is no real need for this test.  We could change
      the condition to "if (temp <= 1) goto done;" but just deleting the test
      is cleanest.
      
      Fixes: 7d50195f
      
       ("usb: host: Faraday fotg210-hcd driver")
      Cc: stable <stable@kernel.org>
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      Reviewed-by: default avatarLee Jones <lee@kernel.org>
      Link: https://lore.kernel.org/r/ZXmwIwHe35wGfgzu@suswa
      
      
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      32d9a4ce
    • Tony Lindgren's avatar
      ARM: dts: Fix occasional boot hang for am3 usb · d529cc22
      Tony Lindgren authored
      [ Upstream commit 9b6a51aa ]
      
      With subtle timings changes, we can now sometimes get an external abort on
      non-linefetch error booting am3 devices at sysc_reset(). This is because
      of a missing reset delay needed for the usb target module.
      
      Looks like we never enabled the delay earlier for am3, although a similar
      issue was seen earlier with a similar usb setup for dm814x as described in
      commit ebf24414 ("ARM: OMAP2+: Use srst_udelay for USB on dm814x").
      
      Cc: stable@vger.kernel.org
      Fixes: 0782e857
      
       ("ARM: dts: Probe am335x musb with ti-sysc")
      Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
      Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
      d529cc22