In the Linux kernel, the following vulnerability has been resolved:
erofs: Fix detection of atomic context
Current check for atomic context is not sufficient as zerofsdecompressqueueendio can be called under rcu lock from blkmqflushplug_list(). See the stacktrace [1]
In such case we should hand off the decompression work for async processing rather than trying to do sync decompression in current context. Patch fixes the detection by checking for rcureadlockanyheld() and while at it use more appropriate !intask() check than inatomic().
Background: Historically erofs would always schedule a kworker for decompression which would incur the scheduling cost regardless of the context. But zerofsdecompressqueueendio() may not always be in atomic context and we could actually benefit from doing the decompression in zerofsdecompressqueueendio() if we are in thread context, for example when running with dm-verity. This optimization was later added in patch [2] which has shown improvement in performance benchmarks.
============================================== [1] Problem stacktrace [name:core&]BUG: sleeping function called from invalid context at kernel/locking/mutex.c:291 [name:core&]inatomic(): 0, irqsdisabled(): 0, nonblock: 0, pid: 1615, name: CpuMonitorServi [name:core&]preemptcount: 0, expected: 0 [name:core&]RCU nest depth: 1, expected: 0 CPU: 7 PID: 1615 Comm: CpuMonitorServi Tainted: G S W OE 6.1.25-android14-5-maybe-dirty-mainline #1 Hardware name: MT6897 (DT) Call trace: dumpbacktrace+0x108/0x15c showstack+0x20/0x30 dumpstacklvl+0x6c/0x8c dumpstack+0x20/0x48 _mightresched+0x1fc/0x308 _mightsleep+0x50/0x88 mutexlock+0x2c/0x110 zerofsdecompressqueue+0x11c/0xc10 zerofsdecompresskickoff+0x110/0x1a4 zerofsdecompressqueueendio+0x154/0x180 bioendio+0x1b0/0x1d8 _dmiocomplete+0x22c/0x280 cloneendio+0xe4/0x280 bioendio+0x1b0/0x1d8 blkupdaterequest+0x138/0x3a4 blkmqplugissuedirect+0xd4/0x19c blkmqflushpluglist+0x2b0/0x354 _blkflushplug+0x110/0x160 blkfinishplug+0x30/0x4c readpages+0x2fc/0x370 pagecacheraunbounded+0xa4/0x23c pagecacheraorder+0x290/0x320 dosyncmmapreadahead+0x108/0x2c0 filemapfault+0x19c/0x52c _dofault+0xc4/0x114 handlemmfault+0x5b4/0x1168 dopagefault+0x338/0x4b4 dotranslationfault+0x40/0x60 domemabort+0x60/0xc8 el0da+0x4c/0xe0 el0t64synchandler+0xd4/0xfc el0t64_sync+0x1a0/0x1a4
[2] Link: https://lore.kernel.org/all/20210317035448.13921-1-huangjianan@oppo.com/