Commit Graph

1150097 Commits

Author SHA1 Message Date
Kees Cook
c2ac612610 BACKPORT: printk: ringbuffer: Fix truncating buffer size min_t cast
If an output buffer size exceeded U16_MAX, the min_t(u16, ...) cast in
copy_data() was causing writes to truncate. This manifested as output
bytes being skipped, seen as %NUL bytes in pstore dumps when the available
record size was larger than 65536. Fix the cast to no longer truncate
the calculation.

Bug: 300230860
(cherry picked from commit 53e9e33ede37a247d926db5e4a9e56b55204e66c)
Change-Id: I1b55761335aba6fa39f00306f7b0255c2afd0849
Cc: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: John Ogness <john.ogness@linutronix.de>
Reported-by: Vijay Balakrishna <vijayb@linux.microsoft.com>
Link: https://lore.kernel.org/lkml/d8bb1ec7-a4c5-43a2-9de0-9643a70b899f@linux.microsoft.com/
Fixes: b6cf8b3f33 ("printk: add lockless ringbuffer")
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Tested-by: Vijay Balakrishna <vijayb@linux.microsoft.com>
Tested-by: Guilherme G. Piccoli <gpiccoli@igalia.com> # Steam Deck
Reviewed-by: Tyler Hicks (Microsoft) <code@tyhicks.com>
Tested-by: Tyler Hicks (Microsoft) <code@tyhicks.com>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20230811054528.never.165-kees@kernel.org
Signed-off-by: Enlin Mu <enlin.mu@unisoc.com>
2023-09-13 11:43:36 +00:00
zhengtangquan
7579b22626 ANDROID: GKI: Add symbols to symbol list for oplus
1 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_killed_process'

1 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_killed_process'

Bug: 232062955
Change-Id: I8ae3cdd8f8b7a953d76349d3299b6b9b87ab8707
Signed-off-by: Tangquan Zheng <zhengtangquan@oppo.com>
2023-09-13 00:04:10 +00:00
zhengtangquan
6e5f182128 ANDROID: signal: Add vendor hook for memory reap
Add vendor hook to determine if the memory of a process
that received the SIGKILL can be reaped.
Partial cherry-pick of aosp/1724512 & aosp/2093626.

Bug: 232062955
Change-Id: I75072bd264df33caff67d083821ee6f33ca83af9
Signed-off-by: Tangquan Zheng <zhengtangquan@oppo.com>
2023-09-13 00:04:10 +00:00
Charan Teja Kalla
3a51a61927 ANDROID: abi_gki_aarch64_qcom: white list symbols for mglru overshoot
Whitelist the below symbols that can be used to decide if overshooting
of kswapd reclaim is allowed.

Symbols added:
  __traceiter_android_vh_scan_abort_check_wmarks
  __tracepoint_android_vh_scan_abort_check_wmarks

Bug: 224956008
Change-Id: I185a570b345d2db0a1426075faa4d9c6325fb0e8
Signed-off-by: Charan Teja Kalla <quic_charante@quicinc.com>
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2023-09-12 23:08:17 +00:00
Kalesh Singh
0500235e3f ANDROID: vendor_hook: Add vendor hook to decide scan abort policy
Allow vendor hook to enable checking of the high water marks to
decide if reclaim should continue scanning.

Bug: 224956008
Change-Id: I63fe1fd386e7599451c2df0a04c8440b4fc142fc
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2023-09-12 23:08:17 +00:00
Kuniyuki Iwashima
e6ed59127c UPSTREAM: af_unix: Fix null-ptr-deref in unix_stream_sendpage().
Bing-Jhong Billy Jheng reported null-ptr-deref in unix_stream_sendpage()
with detailed analysis and a nice repro.

unix_stream_sendpage() tries to add data to the last skb in the peer's
recv queue without locking the queue.

If the peer's FD is passed to another socket and the socket's FD is
passed to the peer, there is a loop between them.  If we close both
sockets without receiving FD, the sockets will be cleaned up by garbage
collection.

The garbage collection iterates such sockets and unlinks skb with
FD from the socket's receive queue under the queue's lock.

So, there is a race where unix_stream_sendpage() could access an skb
locklessly that is being released by garbage collection, resulting in
use-after-free.

To avoid the issue, unix_stream_sendpage() must lock the peer's recv
queue.

Note the issue does not exist in 6.5+ thanks to the recent sendpage()
refactoring.

This patch is originally written by Linus Torvalds.

BUG: unable to handle page fault for address: ffff988004dd6870
PF: supervisor read access in kernel mode
PF: error_code(0x0000) - not-present page
PGD 0 P4D 0
PREEMPT SMP PTI
CPU: 4 PID: 297 Comm: garbage_uaf Not tainted 6.1.46 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/01/2014
RIP: 0010:kmem_cache_alloc_node+0xa2/0x1e0
Code: c0 0f 84 32 01 00 00 41 83 fd ff 74 10 48 8b 00 48 c1 e8 3a 41 39 c5 0f 85 1c 01 00 00 41 8b 44 24 28 49 8b 3c 24 48 8d 4a 40 <49> 8b 1c 06 4c 89 f0 65 48 0f c7 0f 0f 94 c0 84 c0 74 a1 41 8b 44
RSP: 0018:ffffc9000079fac0 EFLAGS: 00000246
RAX: 0000000000000070 RBX: 0000000000000005 RCX: 000000000001a284
RDX: 000000000001a244 RSI: 0000000000400cc0 RDI: 000000000002eee0
RBP: 0000000000400cc0 R08: 0000000000400cc0 R09: 0000000000000003
R10: 0000000000000001 R11: 0000000000000000 R12: ffff888003970f00
R13: 00000000ffffffff R14: ffff988004dd6800 R15: 00000000000000e8
FS:  00007f174d6f3600(0000) GS:ffff88807db00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffff988004dd6870 CR3: 00000000092be000 CR4: 00000000007506e0
PKRU: 55555554
Call Trace:
 <TASK>
 ? __die_body.cold+0x1a/0x1f
 ? page_fault_oops+0xa9/0x1e0
 ? fixup_exception+0x1d/0x310
 ? exc_page_fault+0xa8/0x150
 ? asm_exc_page_fault+0x22/0x30
 ? kmem_cache_alloc_node+0xa2/0x1e0
 ? __alloc_skb+0x16c/0x1e0
 __alloc_skb+0x16c/0x1e0
 alloc_skb_with_frags+0x48/0x1e0
 sock_alloc_send_pskb+0x234/0x270
 unix_stream_sendmsg+0x1f5/0x690
 sock_sendmsg+0x5d/0x60
 ____sys_sendmsg+0x210/0x260
 ___sys_sendmsg+0x83/0xd0
 ? kmem_cache_alloc+0xc6/0x1c0
 ? avc_disable+0x20/0x20
 ? percpu_counter_add_batch+0x53/0xc0
 ? alloc_empty_file+0x5d/0xb0
 ? alloc_file+0x91/0x170
 ? alloc_file_pseudo+0x94/0x100
 ? __fget_light+0x9f/0x120
 __sys_sendmsg+0x54/0xa0
 do_syscall_64+0x3b/0x90
 entry_SYSCALL_64_after_hwframe+0x69/0xd3
RIP: 0033:0x7f174d639a7d
Code: 28 89 54 24 1c 48 89 74 24 10 89 7c 24 08 e8 8a c1 f4 ff 8b 54 24 1c 48 8b 74 24 10 41 89 c0 8b 7c 24 08 b8 2e 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 33 44 89 c7 48 89 44 24 08 e8 de c1 f4 ff 48
RSP: 002b:00007ffcb563ea50 EFLAGS: 00000293 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f174d639a7d
RDX: 0000000000000000 RSI: 00007ffcb563eab0 RDI: 0000000000000007
RBP: 00007ffcb563eb10 R08: 0000000000000000 R09: 00000000ffffffff
R10: 00000000004040a0 R11: 0000000000000293 R12: 00007ffcb563ec28
R13: 0000000000401398 R14: 0000000000403e00 R15: 00007f174d72c000
 </TASK>

Bug: 299922588
Fixes: 869e7c6248 ("net: af_unix: implement stream sendpage support")
Reported-by: Bing-Jhong Billy Jheng <billy@starlabs.sg>
Reviewed-by: Bing-Jhong Billy Jheng <billy@starlabs.sg>
Co-developed-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 790c2f9d15)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: Ied4a40e6ae0e594ef84f36287bc6194602935585
2023-09-12 15:01:22 +01:00
Peter Wang
2eb5b31ac1 FROMLIST: ufs: core: fix abnormal scale up after last cmd finish
When ufshcd_clk_scaling_suspend_work(Thread A) running and new command
coming, ufshcd_clk_scaling_start_busy(Thread B) may get host_lock
after Thread A first time release host_lock. Then Thread A second time
get host_lock will set clk_scaling.window_start_t = 0 which scale up
clock abnormal next polling_ms time.
Also inlines another __ufshcd_suspend_clkscaling calls.

Below is racing step:
1	hba->clk_scaling.suspend_work (Thread A)
	ufshcd_clk_scaling_suspend_work
2		spin_lock_irqsave(hba->host->host_lock, irq_flags);
3		hba->clk_scaling.is_suspended = true;
4		spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
		__ufshcd_suspend_clkscaling
7			spin_lock_irqsave(hba->host->host_lock, flags);
8			hba->clk_scaling.window_start_t = 0;
9			spin_unlock_irqrestore(hba->host->host_lock, flags);

	ufshcd_send_command (Thread B)
		ufshcd_clk_scaling_start_busy
5			spin_lock_irqsave(hba->host->host_lock, flags);
			....
6			spin_unlock_irqrestore(hba->host->host_lock, flags);

Bug: 298004596
Link: https://lore.kernel.org/all/20230831130826.5592-3-peter.wang@mediatek.com/
Change-Id: Ib208b1265107769005c4ae3f72d46b12c072b5c7
Signed-off-by: Peter Wang <peter.wang@mediatek.com>
2023-09-11 20:28:25 +00:00
Peter Wang
89434cbd2d FROMLIST: ufs: core: fix abnormal scale up after scale down
When no active_reqs, devfreq_monitor(Thread A) will suspend clock scaling.
But it may have racing with clk_scaling.suspend_work(Thread B) and
actually not suspend clock scaling(requue after suspend).
Next time after polling_ms, devfreq_monitor read
clk_scaling.window_start_t = 0 then scale up clock abnormal.

Below is racing step:
	devfreq->work (Thread A)
	devfreq_monitor
		update_devfreq
		.....
			ufshcd_devfreq_target
			queue_work(hba->clk_scaling.workq,
1			   &hba->clk_scaling.suspend_work)
		.....
5	queue_delayed_work(devfreq_wq, &devfreq->work,
			msecs_to_jiffies(devfreq->profile->polling_ms));

2	hba->clk_scaling.suspend_work (Thread B)
	ufshcd_clk_scaling_suspend_work
		__ufshcd_suspend_clkscaling
			devfreq_suspend_device(hba->devfreq);
3				cancel_delayed_work_sync(&devfreq->work);
4			hba->clk_scaling.window_start_t = 0;
	.....

Bug: 298004596
Link: https://lore.kernel.org/all/20230831130826.5592-4-peter.wang@mediatek.com/
Change-Id: I3ea77255f1b3845e9dd7bf6b050f3e9ba1f5f3f2
Signed-off-by: Peter Wang <peter.wang@mediatek.com>
2023-09-11 20:28:25 +00:00
Peter Wang
e490b62fed FROMLIST: ufs: core: only suspend clock scaling if scale down
If clock scale up and suspend clock scaling, ufs will keep high
performance/power mode but no read/write requests on going.
It is logic wrong and have power concern.

Bug: 298004596
Link: https://lore.kernel.org/all/20230831130826.5592-2-peter.wang@mediatek.com/
Change-Id: I950ec28a506d7eb83c575d9bd482c41869e73848
Signed-off-by: Peter Wang <peter.wang@mediatek.com>
2023-09-11 20:28:25 +00:00
Suren Baghdasaryan
3ffb038098 ANDROID: GKI: update ABI definition
Regenerate ABU definition file to resolve ABI breakage caused by a
private struct zs_pool:

INFO: ABI DIFFERENCES HAVE BEEN DETECTED!
INFO: type 'struct zs_pool' changed
  member 'atomic_t compaction_in_progress' was added

Bug: 296365608
Change-Id: I477b6dbbdaf464b2fdf3e666b9696f1a79095a63
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2023-09-11 17:21:03 +00:00
Sergey Senozhatsky
e2fa9ebcae UPSTREAM: zsmalloc: allow only one active pool compaction context
zsmalloc pool can be compacted concurrently by many contexts,
e.g.

 cc1 handle_mm_fault()
      do_anonymous_page()
       __alloc_pages_slowpath()
        try_to_free_pages()
         do_try_to_free_pages(
          lru_gen_shrink_node()
           shrink_slab()
            do_shrink_slab()
             zs_shrinker_scan()
              zs_compact()

Pool compaction is currently (basically) single-threaded as
it is performed under pool->lock. Having multiple compaction
threads results in unnecessary contention, as each thread
competes for pool->lock. This, in turn, affects all zsmalloc
operations such as zs_malloc(), zs_map_object(), zs_free(), etc.

Introduce the pool->compaction_in_progress atomic variable,
which ensures that only one compaction context can run at a
time. This reduces overall pool->lock contention in (corner)
cases when many contexts attempt to shrink zspool simultaneously.

Link: https://lkml.kernel.org/r/20230418074639.1903197-1-senozhatsky@chromium.org
Fixes: c0547d0b6a4b ("zsmalloc: consolidate zs_pool's migrate_lock and size_class's locks")
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

(cherry picked from commit cb440cecb2)

Bug: 296365608
Change-Id: Ic7878e08c3484ade8c766d051a8f17cc8179eedf
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2023-09-11 17:20:54 +00:00
Aaro Mäkinen
478ec4dbea ANDROID: GKI: Update Tuxera symbol list
This list covers Microsoft exFAT by Tuxera and Microsoft NTFS by Tuxera file
system drivers.

INFO: 118 function symbol(s) added
  'void __bforget(struct buffer_head*)'
  'void __bh_read_batch(int, struct buffer_head**, blk_opf_t, bool)'
  'ssize_t __blockdev_direct_IO(struct kiocb*, struct inode*, struct block_device*, struct iov_iter*, get_block_t*, dio_iodone_t*, dio_submit_t*, int)'
  'struct buffer_head* __bread_gfp(struct block_device*, sector_t, unsigned int, gfp_t)'
  'void __breadahead(struct block_device*, sector_t, unsigned int)'
  'void __brelse(struct buffer_head*)'
  'void __filemap_set_wb_err(struct address_space*, int)'
  'struct folio* __folio_alloc(gfp_t, unsigned int, int, nodemask_t*)'
  'void __folio_cancel_dirty(struct folio*)'
  'void __insert_inode_hash(struct inode*, unsigned long)'
  'void __mark_inode_dirty(struct inode*, int)'
  'void __remove_inode_hash(struct inode*)'
  'int __set_page_dirty_nobuffers(struct page*)'
  'int __sync_dirty_buffer(struct buffer_head*, blk_opf_t)'
  'void _trace_android_vh_record_pcpu_rwsem_time_early(unsigned long, struct percpu_rw_semaphore*)'
  'struct wait_queue_head* bit_waitqueue(void*, int)'
  'int blkdev_issue_discard(struct block_device*, sector_t, sector_t, gfp_t)'
  'bool block_dirty_folio(struct address_space*, struct folio*)'
  'void block_invalidate_folio(struct folio*, size_t, size_t)'
  'bool block_is_partially_uptodate(struct folio*, size_t, size_t)'
  'int buffer_migrate_folio(struct address_space*, struct folio*, struct folio*, enum migrate_mode)'
  'bool capable_wrt_inode_uidgid(struct user_namespace*, const struct inode*, int)'
  'void clean_bdev_aliases(struct block_device*, sector_t, sector_t)'
  'void clear_inode(struct inode*)'
  'bool clear_page_dirty_for_io(struct page*)'
  'size_t copy_page_from_iter_atomic(struct page*, unsigned int, size_t, struct iov_iter*)'
  'void create_empty_buffers(struct page*, unsigned long, unsigned long)'
  'int current_umask()'
  'struct dentry* d_add_ci(struct dentry*, struct inode*, struct qstr*)'
  'void d_instantiate(struct dentry*, struct inode*)'
  'struct dentry* d_obtain_alias(struct inode*)'
  'struct dentry* d_splice_alias(struct inode*, struct dentry*)'
  'int down_write_trylock(struct rw_semaphore*)'
  'void drop_nlink(struct inode*)'
  'void end_buffer_write_sync(struct buffer_head*, int)'
  'void end_page_writeback(struct page*)'
  'errseq_t errseq_set(errseq_t*, int)'
  'size_t fault_in_iov_iter_readable(const struct iov_iter*, size_t)'
  'size_t fault_in_safe_writeable(const char*, size_t)'
  'int fiemap_fill_next_extent(struct fiemap_extent_info*, u64, u64, u64, u32)'
  'int fiemap_prep(struct inode*, struct fiemap_extent_info*, u64, u64*, u32)'
  'int file_check_and_advance_wb_err(struct file*)'
  'int file_remove_privs(struct file*)'
  'int file_update_time(struct file*)'
  'bool filemap_dirty_folio(struct address_space*, struct folio*)'
  'vm_fault_t filemap_fault(struct vm_fault*)'
  'int filemap_fdatawait_range(struct address_space*, loff_t, loff_t)'
  'int filemap_fdatawrite(struct address_space*)'
  'int filemap_fdatawrite_range(struct address_space*, loff_t, loff_t)'
  'int filemap_flush(struct address_space*)'
  'int filemap_write_and_wait_range(struct address_space*, loff_t, loff_t)'
  'int folio_write_one(struct folio*)'
  'int generic_error_remove_page(struct address_space*, struct page*)'
  'ssize_t generic_file_direct_write(struct kiocb*, struct iov_iter*)'
  'int generic_file_mmap(struct file*, struct vm_area_struct*)'
  'int generic_file_open(struct inode*, struct file*)'
  'ssize_t generic_file_splice_read(struct file*, loff_t*, struct pipe_inode_info*, size_t, unsigned int)'
  'void generic_fillattr(struct user_namespace*, struct inode*, struct kstat*)'
  'ssize_t generic_read_dir(struct file*, char*, size_t, loff_t*)'
  'struct page* grab_cache_page_write_begin(struct address_space*, unsigned long)'
  'struct inode* iget5_locked(struct super_block*, unsigned long, int(*)(struct inode*, void*), int(*)(struct inode*, void*), void*)'
  'struct inode* igrab(struct inode*)'
  'void ihold(struct inode*)'
  'struct inode* ilookup5(struct super_block*, unsigned long, int(*)(struct inode*, void*), void*)'
  'int in_group_p(kgid_t)'
  'void inc_nlink(struct inode*)'
  'void init_special_inode(struct inode*, umode_t, dev_t)'
  'void inode_dio_wait(struct inode*)'
  'void inode_init_once(struct inode*)'
  'void inode_init_owner(struct user_namespace*, struct inode*, const struct inode*, umode_t)'
  'bool inode_maybe_inc_iversion(struct inode*, bool)'
  'int inode_newsize_ok(const struct inode*, loff_t)'
  'void inode_set_flags(struct inode*, unsigned int, unsigned int)'
  'void invalidate_bdev(struct block_device*)'
  'unsigned long iov_iter_alignment(const struct iov_iter*)'
  'ssize_t iov_iter_get_pages2(struct iov_iter*, struct page**, size_t, unsigned int, size_t*)'
  'size_t iov_iter_single_seg_count(const struct iov_iter*)'
  'bool is_bad_inode(struct inode*)'
  'ssize_t iter_file_splice_write(struct pipe_inode_info*, struct file*, loff_t*, size_t, unsigned int)'
  'ino_t iunique(struct super_block*, ino_t)'
  'void kill_block_super(struct super_block*)'
  'void* kmem_cache_alloc_lru(struct kmem_cache*, struct list_lru*, gfp_t)'
  'struct nls_table* load_nls(char*)'
  'struct nls_table* load_nls_default()'
  'void make_bad_inode(struct inode*)'
  'void mark_buffer_async_write(struct buffer_head*)'
  'void mark_buffer_dirty(struct buffer_head*)'
  'void mark_buffer_write_io_error(struct buffer_head*)'
  'struct dentry* mount_bdev(struct file_system_type*, int, const char*, void*, int(*)(struct super_block*, void*, int))'
  'int mpage_read_folio(struct folio*, get_block_t*)'
  'void mpage_readahead(struct readahead_control*, get_block_t*)'
  'int notify_change(struct user_namespace*, struct dentry*, struct iattr*, struct inode**)'
  'unsigned long page_cache_next_miss(struct address_space*, unsigned long, unsigned long)'
  'unsigned long page_cache_prev_miss(struct address_space*, unsigned long, unsigned long)'
  'void page_zero_new_buffers(struct page*, unsigned int, unsigned int)'
  'struct page* pagecache_get_page(struct address_space*, unsigned long, int, gfp_t)'
  'unsigned int pagevec_lookup_range_tag(struct pagevec*, struct address_space*, unsigned long*, unsigned long, xa_mark_t)'
  'bool redirty_page_for_writepage(struct writeback_control*, struct page*)'
  'int sb_min_blocksize(struct super_block*, int)'
  'int sb_set_blocksize(struct super_block*, int)'
  'int security_inode_init_security(struct inode*, struct inode*, const struct qstr*, initxattrs, void*)'
  'void set_nlink(struct inode*, unsigned int)'
  'bool set_page_writeback(struct page*)'
  'int setattr_prepare(struct user_namespace*, struct dentry*, struct iattr*)'
  'int sync_dirty_buffer(struct buffer_head*)'
  'int sync_inode_metadata(struct inode*, int)'
  'void tag_pages_for_writeback(struct address_space*, unsigned long, unsigned long)'
  'struct timespec64 timestamp_truncate(struct timespec64, struct inode*)'
  'void touch_atime(const struct path*)'
  'void truncate_inode_pages(struct address_space*, loff_t)'
  'void truncate_inode_pages_final(struct address_space*)'
  'void truncate_pagecache(struct inode*, loff_t)'
  'void truncate_setsize(struct inode*, loff_t)'
  'void try_to_writeback_inodes_sb(struct super_block*, enum wb_reason)'
  'void unload_nls(struct nls_table*)'
  'void unlock_new_inode(struct inode*)'
  'int wake_bit_function(struct wait_queue_entry*, unsigned int, int, void*)'
  'int write_inode_now(struct inode*, int)'

Bug: 299833811
Change-Id: I51ae5f4b02bab32a913b95b16ab5625ba41458f5
Signed-off-by: Aaro Mäkinen <aaro@tuxera.com>
2023-09-11 16:07:12 +03:00
Prathu Baronia
cd94fe67fd ANDROID: ABI: Update symbols to qcom whitelist
Update whitelist for the symbols used by qcom socs in
abi_gki_aarch64_qcom.

1 function symbol(s) added
	'vhost_dev_flush'

Bug: 299585715

Change-Id: I403394331953c9cfee54b4b0c2a0365a3df5f0af
Signed-off-by: Prathu Baronia <quic_pbaronia@quicinc.com>
Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
2023-09-08 19:29:53 +00:00
RD Babiera
68eefde2d3 UPSTREAM: usb: typec: tcpm: set initial svdm version based on pd revision
When sending Discover Identity messages to a Port Partner that uses Power
Delivery v2 and SVDM v1, we currently send PD v2 messages with SVDM v2.0,
expecting the port partner to respond with its highest supported SVDM
version as stated in Section 6.4.4.2.3 in the Power Delivery v3
specification. However, sending SVDM v2 to some Power Delivery v2 port
partners results in a NAK whereas sending SVDM v1 does not.

NAK messages can be handled by the initiator (PD v3 section 6.4.4.2.5.1),
and one solution could be to resend Discover Identity on a lower SVDM
version if possible. But, Section 6.4.4.3 of PD v2 states that "A NAK
response Should be taken as an indication not to retry that particular
Command."

Instead, we can set the SVDM version to the maximum one supported by the
negotiated PD revision. When operating in PD v2, this obeys Section
6.4.4.2.3, which states the SVDM field "Shall be set to zero to indicate
Version 1.0." In PD v3, the SVDM field "Shall be set to 01b to indicate
Version 2.0."

Fixes: c34e85fa69 ("usb: typec: tcpm: Send DISCOVER_IDENTITY from dedicated work")
Cc: stable@vger.kernel.org
Signed-off-by: RD Babiera <rdbabiera@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20230731165926.1815338-1-rdbabiera@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Bug: 289437937
(cherry picked from commit c97cd0b4b54eb42aed7f6c3c295a2d137f6d2416)
Signed-off-by: RD Babiera <rdbabiera@google.com>
(cherry picked from https://android-review.googlesource.com/q/commit:d02aef1ae51a03b9ab20c8e01ed32593a7ffc6fc)
Merged-In: Ie919c29bab68cb08cb659471ff6106bae502c8dd
Change-Id: Ie919c29bab68cb08cb659471ff6106bae502c8dd
2023-09-08 19:24:11 +00:00
Mostafa Saleh
a68bd01493 ANDROID: KVM: arm64: Don't update IOMMUs for share/unshare
Share/unshare initiated by host doesn't change memory permission, and
as currently pKVM doesn't support device assignment, there is no need
to update the IOMMU unnecessarily as it waste cycles.

Once device assignment is enabled, this assumption will not be valid
as guests have access to DMA.


Bug: 291843613
Change-Id: I28c69ec8f721711d5b59fa2784386fa61654fe5a
Signed-off-by: Mostafa Saleh <smostafa@google.com>
2023-09-08 11:45:45 +00:00
Qais Yousef
20ecb229c5 ANDROID: cpuidle: teo: Export a function that allows modifying util_threshold
There are some corner cases where we do worse in power because the
threshold is too low. Until these cases are better understood and
addressed upstream, provide a function for vendors to override this
value with something more suitable in their modules.

Bug: 289293494
Signed-off-by: Qais Yousef <qyousef@google.com>
Change-Id: I95dd36718a317f3fcb2a9f4bc87dd3390a4f7d7d
2023-09-08 03:14:00 +00:00
Rick Yiu
2490ab50e7 ANDROID: sched: Add vendor hook for rt util update
Vendor may have need to track rt util.

Bug: 201261299
Signed-off-by: Rick Yiu <rickyiu@google.com>
Change-Id: I2f4e5142c6bc8574ee3558042e1fb0dae13b702d
2023-09-08 03:14:00 +00:00
Rick Yiu
6d97f75abc ANDROID: sched: Add vendor hook for util-update related functions
Vendor may have the need to implement their own util tracking.

Bug: 297343949
Signed-off-by: Rick Yiu <rickyiu@google.com>
Change-Id: I973902e6ff82a85ecd029ac5a78692d629df1ebe
2023-09-08 03:14:00 +00:00
Wei Wang
e08c5de06e ANDROID: sched: Add vendor hooks for override sugov behavior
Upstream moved the sugov to DEADLINE class which has higher prio than RT
so it can potentially block many RT use case in Android.

Also currently iowait doesn't distinguish background/foreground tasks
and we have seen cases where device run to high frequency unnecessarily
when running some background I/O.

Bug: 297343949
Signed-off-by: Wei Wang <wvw@google.com>
Change-Id: I21e9bfe9ef75a4178279574389e417c3f38e65ac
2023-09-08 03:14:00 +00:00
Qais Yousef
5762974151 ANDROID: Add new hook to enable overriding uclamp_validate()
We want to add more special values, specifically for uclamp_max so that
it can be set automatically to the most efficient value based on the
core it's running on.

Bug: 297343949
Signed-off-by: Qais Yousef <qyousef@google.com>
Change-Id: I57343c4544f6cac621c855cbb94de0b8d80c51fa
2023-09-08 03:14:00 +00:00
Qais Yousef
b57e3c1d99 ANDROID: sched/uclamp: Don't enable uclamp_is_used static key by in-kernel requests
We do have now in-kernel users of uclamp to implement inheritance. The
static_branch_enable() path unconditionally holds the cpus_read_lock()
which might_sleep(). The path in binder that implements inheritance
happens from in_atomic() context which leads to a splat like this one:

	[  147.529960] BUG: sleeping function called from invalid context at include/linux/percpu-rwsem.h:56
	[  147.530196] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 2586, name: RenderThread
	[  147.530410] INFO: lockdep is turned off.
	[  147.530518] Preemption disabled at:
	[  147.530521] [<ffffffc008ca2cec>] binder_proc_transaction+0x78/0x41c
	[  147.530793] CPU: 8 PID: 2586 Comm: RenderThread Tainted: G S      W  O      5.15.76-android14-5-00086-gc01afe5d262f #1
	[  147.531214] Call trace:
	[  147.531288] dump_backtrace+0xe8/0x134
	[  147.531444] show_stack+0x1c/0x4c
	[  147.531598] dump_stack_lvl+0x74/0x94
	[  147.531766] dump_stack+0x14/0x3c
	[  147.531920] ___might_sleep+0x210/0x230
	[  147.532094] __might_sleep+0x54/0x84
	[  147.532259] cpus_read_lock+0x2c/0x160
	[  147.532429] static_key_enable+0x1c/0x34
	[  147.532608] __sched_setscheduler+0x2a8/0x99c
	[  147.532802] sched_setattr_nocheck+0x1c/0x24
	[  147.532994] binder_do_set_priority+0x31c/0x4a4
	[  147.533195] binder_transaction_priority+0x200/0x3f4
	[  147.533413] binder_proc_transaction+0x220/0x41c
	[  147.533618] binder_transaction+0x1df0/0x234c
	[  147.533812] binder_thread_write+0xd84/0x2398
	[  147.534007] binder_ioctl_write_read+0x19c/0xb28
	[  147.534212] binder_ioctl+0x344/0x1a3c
	[  147.534382] __arm64_sys_ioctl+0x94/0xc8
	[  147.534561] invoke_syscall+0x44/0xf8
	[  147.534729] el0_svc_common+0xc8/0x10c
	[  147.534900] do_el0_svc+0x20/0x28
	[  147.535053] el0_svc+0x58/0xe0
	[  147.535198] el0t_64_sync_handler+0x7c/0xe4
	[  147.535386] el0t_64_sync+0x188/0x18c

Prevent enabling the lock for !user initiated sched_setattr()
operations. Generally we don't expect in-kernel uclamp users.

Bug: 259145692
Signed-off-by: Qais Yousef <qyousef@google.com>
Change-Id: Iac5be139b5ffd39f5e1c0431ce253133d81b98cf
2023-09-08 03:14:00 +00:00
Rick Yiu
2b25d535d0 ANDROID: topology: Add vendor hook for use_amu_fie
Vendors could decide to use amu fie feature or not, such as if they
have some feature that needs amu fie to be disabled.

Bug: 297343949
Change-Id: I6b44ee899c58e7d5a8b2db03a30e3ab14b08f101
Signed-off-by: Rick Yiu <rickyiu@google.com>
2023-09-08 03:14:00 +00:00
Rick Yiu
eb9686932b ANDROID: sched: Export symbols needed for vendor hooks
Bug: 297343949
Change-Id: I0cb65e85b36687bfaae6a185ca373d7fb8de0a77
Signed-off-by: Rick Yiu <rickyiu@google.com>
2023-09-08 03:14:00 +00:00
Bumyong Lee
84131c988b ANDROID: Update symbol list for Exynos Auto SoCs
Update symbol list for Exynos Auto SoCs

Bug: 299219798
Signed-off-by: Bumyong Lee <bumyong.lee@samsung.com>
Change-Id: I2a6a58cdfceb28186ee6a5778ce78e872d06c04f
2023-09-06 19:23:23 +00:00
Florian Westphal
3367abadff UPSTREAM: netfilter: nf_tables: deactivate catchall elements in next generation
[ Upstream commit 90e5b3462efa37b8bba82d7c4e63683856e188af ]

When flushing, individual set elements are disabled in the next
generation via the ->flush callback.

Catchall elements are not disabled.  This is incorrect and may lead to
double-deactivations of catchall elements which then results in memory
leaks:

WARNING: CPU: 1 PID: 3300 at include/net/netfilter/nf_tables.h:1172 nft_map_deactivate+0x549/0x730
CPU: 1 PID: 3300 Comm: nft Not tainted 6.5.0-rc5+ #60
RIP: 0010:nft_map_deactivate+0x549/0x730
 [..]
 ? nft_map_deactivate+0x549/0x730
 nf_tables_delset+0xb66/0xeb0

(the warn is due to nft_use_dec() detecting underflow).

Bug: 298710879
Fixes: aaa31047a6 ("netfilter: nftables: add catch-all set element support")
Reported-by: lonial con <kongln9170@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 00ea7eb1c6)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: I870613042789da3ab44f5f34a240f5dc8c4b25a2
2023-09-06 17:06:09 +00:00
Wei Liu
a891f77b7b ANDROID: GKI: Update symbols to symbol list
step2:Add symbol list for oplus in android/abi_gki_aarch64_oplus

4 function symbol(s) added
  'int __traceiter_net_dev_queue(void*, struct sk_buff*)'
  'int __traceiter_net_dev_xmit(void*, struct sk_buff*, int, struct net_device*, unsigned int)'
  'int __traceiter_netif_receive_skb(void*, struct sk_buff*)'
  'int __traceiter_netif_rx(void*, struct sk_buff*)'

4 variable symbol(s) added
  'struct tracepoint __tracepoint_net_dev_queue'
  'struct tracepoint __tracepoint_net_dev_xmit'
  'struct tracepoint __tracepoint_netif_receive_skb'
  'struct tracepoint __tracepoint_netif_rx'

Bug: 282874982
Change-Id: I7229e887e4733898a147567fd489ffd8d10c45f4
Signed-off-by: Wei Liu <liuwei.a@oppo.com>
2023-09-06 09:46:47 +00:00
Wei Liu
4d8d9522db ANDROID: GKI: Export four symbols in file net/core/net-trace.c
step 1: export the follow symbols in file net/core/net-trace.c
EXPORT_TRACEPOINT_SYMBOL_GPL(net_dev_queue);
EXPORT_TRACEPOINT_SYMBOL_GPL(net_dev_xmit);
EXPORT_TRACEPOINT_SYMBOL_GPL(netif_receive_skb);
EXPORT_TRACEPOINT_SYMBOL_GPL(netif_rx);

step 2: update to symbol list, see link:
https://android-review.googlesource.com/c/kernel/common/+/2742633

Bug: 193384408

Change-Id: I5a247d04000289809db89b609ddaec9af33db041
Signed-off-by: Wei Liu <liuwei.a@oppo.com>
2023-09-06 09:46:47 +00:00
Yu Kuai
3973acfed0 UPSTREAM: blk-ioc: fix recursive spin_lock/unlock_irq() in ioc_clear_queue()
Recursive spin_lock/unlock_irq() is not safe, because spin_unlock_irq()
will enable irq unconditionally:

spin_lock_irq	queue_lock	-> disable irq
spin_lock_irq	ioc->lock
spin_unlock_irq ioc->lock	-> enable irq
/*
 * AA dead lock will be triggered if current context is preempted by irq,
 * and irq try to hold queue_lock again.
 */
spin_unlock_irq queue_lock

Fix this problem by using spin_lock/unlock() directly for 'ioc->lock'.

Fixes: 5a0ac57c48aa ("blk-ioc: protect ioc_destroy_icq() by 'queue_lock'")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230606011438.3743440-1-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

Bug: 285274586
(cherry picked from commit a7cfa0af0c88353b4eb59db5a2a0fbe35329b3f9)
Change-Id: I92433b1c639d20dd0cab6fc495a1b087cfdc8835
Signed-off-by: Pradeep P V K <quic_pragalla@quicinc.com>
2023-09-06 07:41:45 +00:00
Paul Lawrence
523bfe8539 ANDROID: fuse-bpf: Align data structs for 32-bit kernels
BPF is always 64-bit code, so we need to pad the uapi structs to be the
same on 32-bit as 64-bit

Bug: 285477572
Test: Cuttlefish x86_64, x86 and x86 only all boot and load fuseMedia
Change-Id: Idf5b09b2581b8d097048e7d2ff4039cd1806c082
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2023-09-05 21:24:08 +00:00
xiaofeng
9f5a84b955 ANDROID: GKI: Update symbol list for xiaomi
1 symbol(s) added
    export cgroup_threadgroup_rwsem

Bug: 297785167
Change-Id: I8eb493e719f218f2804bdfb5800049c30992f065
Signed-off-by: xiaofeng <xiaofeng5@xiaomi.com>
2023-09-05 21:16:05 +00:00
liuxudong5
176d72d941 ANDROID: vendor_hooks: export cgroup_threadgroup_rwsem
When the task wakes up from percpu_rwsem_wait, it will enter a long
runnable state, which will cause frame loss when the application
starts. In order to solve this problem, we need to let the process
enter the "vip" queue when it is woken up, so we need to set a flag
for the process holding the lock to prove that it is about to hold
the lock. Most of this long runnable state occurs in the
cgroup_threadgroup_rwsem, so we only care cgroup_threadgroup_rwsem,
and cgroup_threadgroup_rwsem should be exported. Finally, if the
semaphore is of cgroup_threadgroup_rwsem type and has a flag,
then let it join the "vip" queue.

Bug: 297785167
Signed-off-by: liuxudong <liuxudong5@xiaomi.com>
Change-Id: I2297dfbc2f2681581241f85a3b4fd59415ea67db
2023-09-05 21:16:05 +00:00
luoyongjie
1fb9e95d46 ANDROID: GKI: add symbol list file for meizu
add abi_gki_aarch64_meizu

INFO: 3 function symbol(s) added
  'int __traceiter_android_rvh_sk_alloc(void*, struct sock*)'
  'int __traceiter_android_rvh_sk_free(void*, struct sock*)'
  'int __traceiter_android_vh_alloc_pages_slowpath(void*, gfp_t, unsigned int, unsigned long)'

3 variable symbol(s) added
  'struct tracepoint __tracepoint_android_rvh_sk_alloc'
  'struct tracepoint __tracepoint_android_rvh_sk_free'
  'struct tracepoint __tracepoint_android_vh_alloc_pages_slowpath'

Bug: 298972064
Change-Id: Ia38dd6adc6aac353d347a0a17db6582879bb3978
Signed-off-by: luoyongjie <luoyongjie1@meizu.com>
2023-09-05 21:14:49 +00:00
Paul Lawrence
8fb9de0877 ANDROID: fuse-bpf: Get correct inode in mkdir
We were getting the inode with the parent inode info
Also change variable names to remove confusion
Also set bpf correctly in new inode

Bug: 293838958
Test: fuse_test, atest ScopedStorageDeviceTest,
	atest CtsScopedStorageHostTest
Change-Id: I0b6a6951599e0d211afd2243daacb98679503448
Signed-off-by: Paul Lawrence <paullawrence@google.com>
2023-09-05 20:31:57 +00:00
Santosh Dronamraju
0fdb44964c ANDROID: ABI: Update allowed list for QCOM
Leaf changes summary: 2 artifacts changed
Changed leaf types summary: 0 leaf type changed
Removed/Changed/Added functions summary: 0 Removed, 0 Changed, 2 Added functions
Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable

2 Added functions:

  [A] 'function unsigned int blk_crypto_keyslot_index(struct blk_crypto_keyslot *slot)'
  [A] 'function bool blk_crypto_register(struct blk_crypto_profile *profile, struct request_queue *q)'

Bug: 299067622

Change-Id: I3b5c9bad658ed88d8bdcdc0ed8c2ef0673d7600f
Signed-off-by: Santosh Dronamraju <quic_sdronamr@quicinc.com>
2023-09-05 17:00:08 +00:00
Yu Kuai
404522c763 UPSTREAM: blk-ioc: protect ioc_destroy_icq() by 'queue_lock'
Currently, icq is tracked by both request_queue(icq->q_node) and
task(icq->ioc_node), and ioc_clear_queue() from elevator exit is not
safe because it can access the list without protection:

ioc_clear_queue			ioc_release_fn
 lock queue_lock
 list_splice
 /* move queue list to a local list */
 unlock queue_lock
 /*
  * lock is released, the local list
  * can be accessed through task exit.
  */

				lock ioc->lock
				while (!hlist_empty)
				 icq = hlist_entry
				 lock queue_lock
				  ioc_destroy_icq
				   delete icq->ioc_node
 while (!list_empty)
  icq = list_entry()		   list_del icq->q_node
  /*
   * This is not protected by any lock,
   * list_entry concurrent with list_del
   * is not safe.
   */

				 unlock queue_lock
				unlock ioc->lock

Fix this problem by protecting list 'icq->q_node' by queue_lock from
ioc_clear_queue().

Reported-and-tested-by: Pradeep Pragallapati <quic_pragalla@quicinc.com>
Link: https://lore.kernel.org/lkml/20230517084434.18932-1-quic_pragalla@quicinc.com/
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230531073435.2923422-1-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

Bug: 285274586
(cherry picked from commit 5a0ac57c48aa9380126bd9bf3ec82140aab84548)
Change-Id: I60f3acfaa32f18bed58c8190178cdca5ebd91100
Signed-off-by: Pradeep P V K <quic_pragalla@quicinc.com>
2023-09-05 15:27:33 +00:00
Wei Liu
bd0308e36b ANDROID: GKI: Update symbols to symbol list
Update symbols to symbol list externed by oppo network group.

5 Added function:

  [A] 'function int __rtnl_link_register(rtnl_link_ops*)'
  [A] 'function int ip_local_deliver(struct sk_buff *)'
  [A] 'function iov_iter_advance(struct iov_iter *i, size_t size)'
  [A] 'function int nf_register_net_hook(struct net *net,
					 const struct nf_hook_ops *reg)'
  [A] 'function void nf_unregister_net_hook(struct net *,
					    const struct nf_hook_ops *)'

These functions have been merged in lower versions of the kernel and are still needed by oppo in higher versions.

These functions are needed by other modules that provide functionality for oppo's network, such as the network tracking module, the network warm-up module, etc.

Bug: 297979024

Change-Id: Ic1a4c869b3894a06f7cab7b5120574ed94d519b2
Signed-off-by: Wei Liu <liuwei.a@oppo.com>
2023-09-05 12:38:42 +00:00
John Stultz
87647c0c54 ANDROID: uid_sys_stats: Use llist for deferred work
A use-after-free bug was found in the previous custom lock-free list
implementation for the deferred work, so switch functionality to llist
implementation.

While the previous approach atomically handled the list head, it did not
assure the new node's next pointer was assigned before the head was
pointed to the node, allowing the consumer to traverse to an invalid
next pointer.

Additionally, in switching to llists, this patch pulls the entire list
off the list head once and processes it separately, reducing the number
of atomic operations compared with the custom lists's implementation
which pulled one node at a time atomically from the list head.

BUG: KASAN: use-after-free in process_notifier+0x270/0x2dc
Write of size 8 at addr d4ffff89545c3c58 by task Blocking Thread/3431
Pointer tag: [d4], memory tag: [fe]

call trace:
 dump_backtrace+0xf8/0x118
 show_stack+0x18/0x24
 dump_stack_lvl+0x60/0x78
 print_report+0x178/0x470
 kasan_report+0x8c/0xbc
 kasan_tag_mismatch+0x28/0x3c
 __hwasan_tag_mismatch+0x30/0x60
 process_notifier+0x270/0x2dc
 notifier_call_chain+0xb4/0x108
 blocking_notifier_call_chain+0x54/0x80
 profile_task_exit+0x20/0x2c
 do_exit+0xec/0x1114
 __arm64_sys_exit_group+0x0/0x24
 get_signal+0x93c/0xa78
 do_notify_resume+0x158/0x3fc
 el0_svc+0x54/0x78
 el0t_64_sync_handler+0x44/0xe4
 el0t_64_sync+0x190/0x194

Bug: 294468796
Bug: 295787403
Fixes: 8e86825eec ("ANDROID: uid_sys_stats: Use a single work for deferred updates")
Change-Id: Id377348c239ec720a5237726bc3632544d737e3b
Signed-off-by: John Stultz <jstultz@google.com>
[nkapron: Squashed with other changes and rewrote the commit message]
Signed-off-by: Neill Kapron <nkapron@google.com>
2023-09-05 12:07:09 +00:00
Lin Ma
4b3ab91671 UPSTREAM: net: nfc: Fix use-after-free caused by nfc_llcp_find_local
[ Upstream commit 6709d4b7bc2e079241fdef15d1160581c5261c10 ]

This commit fixes several use-after-free that caused by function
nfc_llcp_find_local(). For example, one UAF can happen when below buggy
time window occurs.

// nfc_genl_llc_get_params   | // nfc_unregister_device
                             |
dev = nfc_get_device(idx);   | device_lock(...)
if (!dev)                    | dev->shutting_down = true;
    return -ENODEV;          | device_unlock(...);
                             |
device_lock(...);            |   // nfc_llcp_unregister_device
                             |   nfc_llcp_find_local()
nfc_llcp_find_local(...);    |
                             |   local_cleanup()
if (!local) {                |
    rc = -ENODEV;            |     // nfc_llcp_local_put
    goto exit;               |     kref_put(.., local_release)
}                            |
                             |       // local_release
                             |       list_del(&local->list)
  // nfc_genl_send_params    |       kfree()
  local->dev->idx !!!UAF!!!  |
                             |

and the crash trace for the one of the discussed UAF like:

BUG: KASAN: slab-use-after-free in nfc_genl_llc_get_params+0x72f/0x780  net/nfc/netlink.c:1045
Read of size 8 at addr ffff888105b0e410 by task 20114

Call Trace:
 <TASK>
 __dump_stack  lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x72/0xa0  lib/dump_stack.c:106
 print_address_description  mm/kasan/report.c:319 [inline]
 print_report+0xcc/0x620  mm/kasan/report.c:430
 kasan_report+0xb2/0xe0  mm/kasan/report.c:536
 nfc_genl_send_params  net/nfc/netlink.c:999 [inline]
 nfc_genl_llc_get_params+0x72f/0x780  net/nfc/netlink.c:1045
 genl_family_rcv_msg_doit.isra.0+0x1ee/0x2e0  net/netlink/genetlink.c:968
 genl_family_rcv_msg  net/netlink/genetlink.c:1048 [inline]
 genl_rcv_msg+0x503/0x7d0  net/netlink/genetlink.c:1065
 netlink_rcv_skb+0x161/0x430  net/netlink/af_netlink.c:2548
 genl_rcv+0x28/0x40  net/netlink/genetlink.c:1076
 netlink_unicast_kernel  net/netlink/af_netlink.c:1339 [inline]
 netlink_unicast+0x644/0x900  net/netlink/af_netlink.c:1365
 netlink_sendmsg+0x934/0xe70  net/netlink/af_netlink.c:1913
 sock_sendmsg_nosec  net/socket.c:724 [inline]
 sock_sendmsg+0x1b6/0x200  net/socket.c:747
 ____sys_sendmsg+0x6e9/0x890  net/socket.c:2501
 ___sys_sendmsg+0x110/0x1b0  net/socket.c:2555
 __sys_sendmsg+0xf7/0x1d0  net/socket.c:2584
 do_syscall_x64  arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3f/0x90  arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x72/0xdc
RIP: 0033:0x7f34640a2389
RSP: 002b:00007f3463415168 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007f34641c1f80 RCX: 00007f34640a2389
RDX: 0000000000000000 RSI: 0000000020000240 RDI: 0000000000000006
RBP: 00007f34640ed493 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffe38449ecf R14: 00007f3463415300 R15: 0000000000022000
 </TASK>

Allocated by task 20116:
 kasan_save_stack+0x22/0x50  mm/kasan/common.c:45
 kasan_set_track+0x25/0x30  mm/kasan/common.c:52
 ____kasan_kmalloc  mm/kasan/common.c:374 [inline]
 __kasan_kmalloc+0x7f/0x90  mm/kasan/common.c:383
 kmalloc  include/linux/slab.h:580 [inline]
 kzalloc  include/linux/slab.h:720 [inline]
 nfc_llcp_register_device+0x49/0xa40  net/nfc/llcp_core.c:1567
 nfc_register_device+0x61/0x260  net/nfc/core.c:1124
 nci_register_device+0x776/0xb20  net/nfc/nci/core.c:1257
 virtual_ncidev_open+0x147/0x230  drivers/nfc/virtual_ncidev.c:148
 misc_open+0x379/0x4a0  drivers/char/misc.c:165
 chrdev_open+0x26c/0x780  fs/char_dev.c:414
 do_dentry_open+0x6c4/0x12a0  fs/open.c:920
 do_open  fs/namei.c:3560 [inline]
 path_openat+0x24fe/0x37e0  fs/namei.c:3715
 do_filp_open+0x1ba/0x410  fs/namei.c:3742
 do_sys_openat2+0x171/0x4c0  fs/open.c:1356
 do_sys_open  fs/open.c:1372 [inline]
 __do_sys_openat  fs/open.c:1388 [inline]
 __se_sys_openat  fs/open.c:1383 [inline]
 __x64_sys_openat+0x143/0x200  fs/open.c:1383
 do_syscall_x64  arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3f/0x90  arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x72/0xdc

Freed by task 20115:
 kasan_save_stack+0x22/0x50  mm/kasan/common.c:45
 kasan_set_track+0x25/0x30  mm/kasan/common.c:52
 kasan_save_free_info+0x2e/0x50  mm/kasan/generic.c:521
 ____kasan_slab_free  mm/kasan/common.c:236 [inline]
 ____kasan_slab_free  mm/kasan/common.c:200 [inline]
 __kasan_slab_free+0x10a/0x190  mm/kasan/common.c:244
 kasan_slab_free  include/linux/kasan.h:162 [inline]
 slab_free_hook  mm/slub.c:1781 [inline]
 slab_free_freelist_hook  mm/slub.c:1807 [inline]
 slab_free  mm/slub.c:3787 [inline]
 __kmem_cache_free+0x7a/0x190  mm/slub.c:3800
 local_release  net/nfc/llcp_core.c:174 [inline]
 kref_put  include/linux/kref.h:65 [inline]
 nfc_llcp_local_put  net/nfc/llcp_core.c:182 [inline]
 nfc_llcp_local_put  net/nfc/llcp_core.c:177 [inline]
 nfc_llcp_unregister_device+0x206/0x290  net/nfc/llcp_core.c:1620
 nfc_unregister_device+0x160/0x1d0  net/nfc/core.c:1179
 virtual_ncidev_close+0x52/0xa0  drivers/nfc/virtual_ncidev.c:163
 __fput+0x252/0xa20  fs/file_table.c:321
 task_work_run+0x174/0x270  kernel/task_work.c:179
 resume_user_mode_work  include/linux/resume_user_mode.h:49 [inline]
 exit_to_user_mode_loop  kernel/entry/common.c:171 [inline]
 exit_to_user_mode_prepare+0x108/0x110  kernel/entry/common.c:204
 __syscall_exit_to_user_mode_work  kernel/entry/common.c:286 [inline]
 syscall_exit_to_user_mode+0x21/0x50  kernel/entry/common.c:297
 do_syscall_64+0x4c/0x90  arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x72/0xdc

Last potentially related work creation:
 kasan_save_stack+0x22/0x50  mm/kasan/common.c:45
 __kasan_record_aux_stack+0x95/0xb0  mm/kasan/generic.c:491
 kvfree_call_rcu+0x29/0xa80  kernel/rcu/tree.c:3328
 drop_sysctl_table+0x3be/0x4e0  fs/proc/proc_sysctl.c:1735
 unregister_sysctl_table.part.0+0x9c/0x190  fs/proc/proc_sysctl.c:1773
 unregister_sysctl_table+0x24/0x30  fs/proc/proc_sysctl.c:1753
 neigh_sysctl_unregister+0x5f/0x80  net/core/neighbour.c:3895
 addrconf_notify+0x140/0x17b0  net/ipv6/addrconf.c:3684
 notifier_call_chain+0xbe/0x210  kernel/notifier.c:87
 call_netdevice_notifiers_info+0xb5/0x150  net/core/dev.c:1937
 call_netdevice_notifiers_extack  net/core/dev.c:1975 [inline]
 call_netdevice_notifiers  net/core/dev.c:1989 [inline]
 dev_change_name+0x3c3/0x870  net/core/dev.c:1211
 dev_ifsioc+0x800/0xf70  net/core/dev_ioctl.c:376
 dev_ioctl+0x3d9/0xf80  net/core/dev_ioctl.c:542
 sock_do_ioctl+0x160/0x260  net/socket.c:1213
 sock_ioctl+0x3f9/0x670  net/socket.c:1316
 vfs_ioctl  fs/ioctl.c:51 [inline]
 __do_sys_ioctl  fs/ioctl.c:870 [inline]
 __se_sys_ioctl  fs/ioctl.c:856 [inline]
 __x64_sys_ioctl+0x19e/0x210  fs/ioctl.c:856
 do_syscall_x64  arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x3f/0x90  arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x72/0xdc

The buggy address belongs to the object at ffff888105b0e400
 which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 16 bytes inside of
 freed 1024-byte region [ffff888105b0e400, ffff888105b0e800)

The buggy address belongs to the physical page:
head:ffffea000416c200 order:3 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x200000000010200(slab|head|node=0|zone=2)
raw: 0200000000010200 ffff8881000430c0 ffffea00044c7010 ffffea0004510e10
raw: 0000000000000000 00000000000a000a 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff888105b0e300: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888105b0e380: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888105b0e400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                         ^
 ffff888105b0e480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888105b0e500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb

In summary, this patch solves those use-after-free by

1. Re-implement the nfc_llcp_find_local(). The current version does not
grab the reference when getting the local from the linked list.  For
example, the llcp_sock_bind() gets the reference like below:

// llcp_sock_bind()

    local = nfc_llcp_find_local(dev); // A
    ..... \
           | raceable
    ..... /
    llcp_sock->local = nfc_llcp_local_get(local); // B

There is an apparent race window that one can  drop the reference
and free the local object fetched in (A) before (B) gets the reference.

2. Some callers of the nfc_llcp_find_local() do not grab the reference
at all. For example, the nfc_genl_llc_{{get/set}_params/sdreq} functions.
We add the nfc_llcp_local_put() for them. Moreover, we add the necessary
error handling function to put the reference.

3. Add the nfc_llcp_remove_local() helper. The local object is removed
from the linked list in local_release() when all reference is gone. This
patch removes it when nfc_llcp_unregister_device() is called.

Therefore, every caller of nfc_llcp_find_local() will get a reference
even when the nfc_llcp_unregister_device() is called. This promises no
use-after-free for the local object is ever possible.

Bug: 294167961
Fixes: 52feb444a9 ("NFC: Extend netlink interface for LTO, RW, and MIUX parameters support")
Fixes: c7aa12252f ("NFC: Take a reference on the LLCP local pointer when creating a socket")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 425d9d3a92)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: I8e7e7101ce0d5c81da9b8febd4ad78dd1affc4a5
2023-09-04 12:09:23 +01:00
Pablo Neira Ayuso
c603880bd5 UPSTREAM: netfilter: nf_tables: disallow rule addition to bound chain via NFTA_RULE_CHAIN_ID
[ Upstream commit 0ebc1064e4874d5987722a2ddbc18f94aa53b211 ]

Bail out with EOPNOTSUPP when adding rule to bound chain via
NFTA_RULE_CHAIN_ID. The following warning splat is shown when
adding a rule to a deleted bound chain:

 WARNING: CPU: 2 PID: 13692 at net/netfilter/nf_tables_api.c:2013 nf_tables_chain_destroy+0x1f7/0x210 [nf_tables]
 CPU: 2 PID: 13692 Comm: chain-bound-rul Not tainted 6.1.39 #1
 RIP: 0010:nf_tables_chain_destroy+0x1f7/0x210 [nf_tables]

Bug: 296128351
Fixes: d0e2c7de92 ("netfilter: nf_tables: add NFT_CHAIN_BINDING")
Reported-by: Kevin Rich <kevinrich1337@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 268cb07ef3)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: Icf97f57d18bb2b30ed28a3de6cdd18661d7f1c3d
2023-09-04 09:47:17 +00:00
Laszlo Ersek
d95b2b008e UPSTREAM: net: tap_open(): set sk_uid from current_fsuid()
commit 5c9241f3ceab3257abe2923a59950db0dc8bb737 upstream.

Commit 66b2c338adce initializes the "sk_uid" field in the protocol socket
(struct sock) from the "/dev/tapX" device node's owner UID. Per original
commit 86741ec254 ("net: core: Add a UID field to struct sock.",
2016-11-04), that's wrong: the idea is to cache the UID of the userspace
process that creates the socket. Commit 86741ec254 mentions socket() and
accept(); with "tap", the action that creates the socket is
open("/dev/tapX").

Therefore the device node's owner UID is irrelevant. In most cases,
"/dev/tapX" will be owned by root, so in practice, commit 66b2c338adce has
no observable effect:

- before, "sk_uid" would be zero, due to undefined behavior
  (CVE-2023-1076),

- after, "sk_uid" would be zero, due to "/dev/tapX" being owned by root.

What matters is the (fs)UID of the process performing the open(), so cache
that in "sk_uid".

Bug: 295995961
Cc: Eric Dumazet <edumazet@google.com>
Cc: Lorenzo Colitti <lorenzo@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Pietro Borrello <borrello@diag.uniroma1.it>
Cc: netdev@vger.kernel.org
Cc: stable@vger.kernel.org
Fixes: 66b2c338adce ("tap: tap_open(): correctly initialize socket uid")
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2173435
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 767800fc40)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: Ib5f80015e5c0280acf9f35124d3ff267ff0420f0
2023-09-04 09:44:46 +00:00
Heikki Krogerus
b15c3a3df0 UPSTREAM: usb: typec: ucsi: Fix command cancellation
The Cancel command was passed to the write callback as the
offset instead of as the actual command which caused NULL
pointer dereference.

Reported-by: Stephan Bolten <stephan.bolten@gmx.net>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217517
Fixes: 094902bc6a ("usb: typec: ucsi: Always cancel the command if PPM reports BUSY condition")
Cc: stable@vger.kernel.org
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Message-ID: <20230606115802.79339-1-heikki.krogerus@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Bug: 298597334
Change-Id: I7f23e49c58b566f462ba34f76966db662308a5bc
(cherry picked from commit c4a8bfabefed706bb9150867db528ceefd5cb5fe)
Signed-off-by: Udipto Goswami <quic_ugoswami@quicinc.com>
2023-09-01 09:53:15 +00:00
Will Shiu
0c34d588af UPSTREAM: locks: fix KASAN: use-after-free in trace_event_raw_event_filelock_lock
As following backtrace, the struct file_lock request , in posix_lock_inode
is free before ftrace function using.
Replace the ftrace function ahead free flow could fix the use-after-free
issue.

[name:report&]===============================================
BUG:KASAN: use-after-free in trace_event_raw_event_filelock_lock+0x80/0x12c
[name:report&]Read at addr f6ffff8025622620 by task NativeThread/16753
[name:report_hw_tags&]Pointer tag: [f6], memory tag: [fe]
[name:report&]
BT:
Hardware name: MT6897 (DT)
Call trace:
 dump_backtrace+0xf8/0x148
 show_stack+0x18/0x24
 dump_stack_lvl+0x60/0x7c
 print_report+0x2c8/0xa08
 kasan_report+0xb0/0x120
 __do_kernel_fault+0xc8/0x248
 do_bad_area+0x30/0xdc
 do_tag_check_fault+0x1c/0x30
 do_mem_abort+0x58/0xbc
 el1_abort+0x3c/0x5c
 el1h_64_sync_handler+0x54/0x90
 el1h_64_sync+0x68/0x6c
 trace_event_raw_event_filelock_lock+0x80/0x12c
 posix_lock_inode+0xd0c/0xd60
 do_lock_file_wait+0xb8/0x190
 fcntl_setlk+0x2d8/0x440
...
[name:report&]
[name:report&]Allocated by task 16752:
...
 slab_post_alloc_hook+0x74/0x340
 kmem_cache_alloc+0x1b0/0x2f0
 posix_lock_inode+0xb0/0xd60
...
 [name:report&]
 [name:report&]Freed by task 16752:
...
  kmem_cache_free+0x274/0x5b0
  locks_dispose_list+0x3c/0x148
  posix_lock_inode+0xc40/0xd60
    do_lock_file_wait+0xb8/0x190
  fcntl_setlk+0x2d8/0x440
  do_fcntl+0x150/0xc18
...

Bug: 290585450
Link:https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git/commit/?h=locks-6.6&id=74f6f5912693ce454384eaeec48705646a21c74f
(cherry picked from commit 74f6f5912693ce454384eaeec48705646a21c74f)
Change-Id: I7daa6e72d1815daff30dd39726e14b1d57b60f5f
Signed-off-by: Will Shiu <Will.Shiu@mediatek.com>
2023-08-31 21:20:34 +00:00
Ramji Jiyani
20266a0652 ANDROID: kleaf: Remove ptp_kvm.ko from i386 modules
commit 638804ea1c ("ANDROID: kleaf: get_gki_modules_list add i386
option") introduced i386 as an option for get_gki_modules_list()
with ptp_kvm.ko as i386 module. ptp_kvm.ko is not a module on
anrdoid14-6.1, and cherry pick from android15-6.1 should have been worked to remove it.

Remove ptp_kvm.ko from i386 list and make it empty for android14-6.1.

Fixes: 638804ea1c ("ANDROID: kleaf: get_gki_modules_list add i386 option")
Bug: 293529933
Test: TH
Change-Id: Ied9d8c06c9f38dc271d541275afee053a87ecd79
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
2023-08-31 17:47:21 +00:00
zhengtangquan
ce18fe6f29 ANDROID: GKI: Add symbols to symbol list for oplus
1 function symbol(s) added
  'int __traceiter_android_vh_tune_swappiness(void*, int*)'

1 variable symbol(s) added
  'struct tracepoint __tracepoint_android_vh_tune_swappiness'

Bug: 297985476
Change-Id: I63e0e77b71df1b81eaa7d7370c6f739337d6c7e3
Signed-off-by: Tangquan Zheng <zhengtangquan@oppo.com>
2023-08-31 17:38:17 +00:00
Tangquan Zheng
8e6550add2 ANDROID: vendor_hooks: Add tune swappiness hook in get_scan_count()
Add hook in get_scan_count() for customized swappiness.
Partial cherry-pick of aosp/2119426.

Bug: 297985476

Change-Id: I9d4074cf1a4097ff2a96be04646a01624cbd8dc3
Signed-off-by: Tangquan Zheng <zhengtangquan@oppo.com>
2023-08-31 17:38:17 +00:00
ying zuxin
dd87a7122c ANDROID: GKI: Update symbol list for VIVO
INFO: 1 function symbol(s) added
  'void blk_fill_rwbs(char*, blk_opf_t)'

Bug: 298155651
Change-Id: If30ac266aff8ba370e3064a59f082a02035c9dff
Signed-off-by: ying zuxin <yingzuxin@vivo.com>
2023-08-31 13:09:07 +00:00
Ramji Jiyani
638804ea1c ANDROID: kleaf: get_gki_modules_list add i386 option
Adds "i386" as an option to get the list of 32-bit x86
modules in get_gki_modules_list().

virtual_device_i686 Cuttlefish target is a consumer.
Option is named i386 to match the `arch` attributes
in kernel_build rule.

Bug: 293529933
Test: TH
Change-Id: Ic5278aa687999a2bb2d98b97b204b99d1fcd809a
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
(cherry picked from commit 2a9967e15f99010ec06ac089b42a2ac20f2a57cb)
2023-08-31 03:24:10 +00:00
Ramji Jiyani
264e2973a4 ANDROID: arm as an option for get_gki_modules_list
If driver config depends on ARM64, driver is not
available for the ARM targets as module.

Introduce arm as an option for get_gki_modules_list()
to separate ARM64 dependent modules.

virtual_device_arm Cuttlefish target is the current
consumer of this; and it fails when there is ARM64
dependent module is introduced like OEM hypervisors.

Bug: 293529933
Test: TH
Change-Id: I462e8968faa48d58721d884688af62ff603c9a3d
Signed-off-by: Ramji Jiyani <ramjiyani@google.com>
(cherry picked from commit b0e30c021b79d9cb9a67b12a94d1fe2f61126f14)
2023-08-31 03:21:33 +00:00
David Gow
37edfbc5c4 UPSTREAM: um: Only disable SSE on clang to work around old GCC bugs
As part of the Rust support for UML, we disable SSE (and similar flags)
to match the normal x86 builds. This both makes sense (we ideally want a
similar configuration to x86), and works around a crash bug with SSE
generation under Rust with LLVM.

However, this breaks compiling stdlib.h under gcc < 11, as the x86_64
ABI requires floating-point return values be stored in an SSE register.
gcc 11 fixes this by only doing register allocation when a function is
actually used, and since we never use atof(), it shouldn't be a problem:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99652

Nevertheless, only disable SSE on clang setups, as that's a simple way
of working around everyone's bugs.

Fixes: 884981867947 ("rust: arch/um: Disable FP/SIMD instruction to match x86")
Reported-by: Roberto Sassu <roberto.sassu@huaweicloud.com>
Link: https://lore.kernel.org/linux-um/6df2ecef9011d85654a82acd607fdcbc93ad593c.camel@huaweicloud.com/
Tested-by: Roberto Sassu <roberto.sassu@huaweicloud.com>
Tested-by: SeongJae Park <sj@kernel.org>
Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Tested-by: Arthur Grillo <arthurgrillo@riseup.net>
Signed-off-by: Richard Weinberger <richard@nod.at>

Bug: 296671039
Change-Id: Ie71e5c59ca9fb6a480895af233fae9a15f5c5ddc
(cherry picked from commit a3046a618a284579d1189af8711765f553eed707)
Signed-off-by: Dongseok Yi <dseok.yi@samsung.com>
2023-08-30 12:58:15 +00:00
Pratyush Brahma
2a13641a14 ANDROID: GKI: Update abi_gki_aarch64_qcom for page_owner symbols
Update abi_gki_aarch64_qcom to include __set_page_owner
and page_owner_inited symbols.

Bug: 296348400
Change-Id: I3dec65fb596764e51897dd0251aada539a34feca
Signed-off-by: Pratyush Brahma <quic_pbrahma@quicinc.com>
2023-08-29 23:06:24 +00:00