android_kernel_xiaomi_sm8450/block
Eric Biggers e7bfca1670 BACKPORT: FROMGIT: blk-mq: release crypto keyslot before reporting I/O complete
Once all I/O using a blk_crypto_key has completed, filesystems can call
blk_crypto_evict_key().  However, the block layer currently doesn't call
blk_crypto_put_keyslot() until the request is being freed, which happens
after upper layers have been told (via bio_endio()) the I/O has
completed.  This causes a race condition where blk_crypto_evict_key()
can see 'slot_refs != 0' without there being an actual bug.

This makes __blk_crypto_evict_key() hit the
'WARN_ON_ONCE(atomic_read(&slot->slot_refs) != 0)' and return without
doing anything, eventually causing a use-after-free in
blk_crypto_reprogram_all_keys().  (This is a very rare bug and has only
been seen when per-file keys are being used with fscrypt.)

There are two options to fix this: either release the keyslot before
bio_endio() is called on the request's last bio, or make
__blk_crypto_evict_key() ignore slot_refs.  Let's go with the first
solution, since it preserves the ability to report bugs (via
WARN_ON_ONCE) where a key is evicted while still in-use.

Fixes: a892c8d52c ("block: Inline encryption support for blk-mq")
Cc: stable@vger.kernel.org
Reviewed-by: Nathan Huckleberry <nhuck@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Link: https://lore.kernel.org/r/20230315183907.53675-2-ebiggers@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

Bug: 270098322
(cherry picked from commit 9cd1e566676bbcb8a126acd921e4e194e6339603
 https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git/log/?h=for-next)
Change-Id: Ic2c2426db7693a06901c7893d481471f30de03b2
Signed-off-by: Eric Biggers <ebiggers@google.com>
2023-03-29 20:05:47 +00:00
..
partitions block: unhash blkdev part inode when the part is deleted 2022-12-08 11:23:59 +01:00
badblocks.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
bfq-cgroup.c block, bfq: fix null pointer dereference in bfq_bio_bfqg() 2022-12-02 17:39:58 +01:00
bfq-iosched.c This is the 5.10.154 stable release 2022-11-29 23:38:14 +00:00
bfq-iosched.h bfq: Get rid of __bio_blkcg() usage 2022-06-09 10:21:31 +02:00
bfq-wf2q.c bfq: fix blkio cgroup leakage v4 2020-08-18 07:48:08 -07:00
bio-integrity.c block: bio-integrity: Advance seed correctly for larger interval sizes 2022-02-08 18:30:35 +01:00
bio.c block: fix infinite loop for invalid zone append 2022-08-21 15:15:34 +02:00
blk-cgroup-rwstat.c blk-cgroup: Fix the recursive blkg rwstat 2021-03-30 14:31:48 +02:00
blk-cgroup-rwstat.h
blk-cgroup.c Merge 5.10.167 into android12-5.10-lts 2023-02-17 15:21:25 +00:00
blk-core.c BACKPORT: FROMGIT: blk-mq: release crypto keyslot before reporting I/O complete 2023-03-29 20:05:47 +00:00
blk-crypto-fallback.c Merge commit 382625d0d4 ("Merge tag 'for-5.9/block-20200802' of git://git.kernel.dk/linux-block") into android-mainline 2020-08-06 10:07:17 -07:00
blk-crypto-internal.h BACKPORT: FROMGIT: blk-mq: release crypto keyslot before reporting I/O complete 2023-03-29 20:05:47 +00:00
blk-crypto.c BACKPORT: FROMGIT: blk-mq: release crypto keyslot before reporting I/O complete 2023-03-29 20:05:47 +00:00
blk-exec.c block: add a blk_account_io_merge_bio helper 2020-05-27 05:21:23 -06:00
blk-flush.c block: Fix fsync always failed if once failed 2022-01-27 10:54:30 +01:00
blk-integrity.c block: flush the integrity workqueue in blk_integrity_unregister 2021-09-30 10:11:06 +02:00
blk-ioc.c block: remove retry loop in ioc_release_fn() 2020-07-16 10:22:15 -06:00
blk-iocost.c iocost: don't reset the inuse weight of under-weighted debtors 2022-05-09 09:05:00 +02:00
blk-iolatency.c blk-iolatency: Fix inflight count imbalances and IO hangs on offline 2022-06-09 10:21:29 +02:00
blk-ioprio.c FROMGIT: block: Introduce the ioprio rq-qos policy 2021-07-01 22:31:51 -07:00
blk-ioprio.h FROMGIT: block: Introduce the ioprio rq-qos policy 2021-07-01 22:31:51 -07:00
blk-lib.c block: add a bdev_is_partition helper 2020-09-25 08:18:57 -06:00
blk-map.c block-map: add __GFP_ZERO flag for alloc_page in function bio_copy_kern 2022-05-12 12:25:45 +02:00
blk-merge.c BACKPORT: FROMGIT: blk-mq: release crypto keyslot before reporting I/O complete 2023-03-29 20:05:47 +00:00
blk-mq-cpumap.c blk-mq: remove the calling of local_memory_node() 2020-10-20 07:08:17 -06:00
blk-mq-debugfs-zoned.c
blk-mq-debugfs.c This is the 5.10.137 stable release 2022-08-29 16:53:14 +02:00
blk-mq-debugfs.h
blk-mq-pci.c
blk-mq-rdma.c
blk-mq-sched.c Revert "block: remove the request_queue to argument request based tracepoints" 2022-08-30 12:56:06 +02:00
blk-mq-sched.h block-5.10-2020-10-12 2020-10-13 12:12:44 -07:00
blk-mq-sysfs.c blk-mq: fix possible memleak when register 'hctx' failed 2023-01-14 10:16:19 +01:00
blk-mq-tag.c blk-mq: avoid to iterate over stale request 2021-09-30 10:11:05 +02:00
blk-mq-tag.h blk-mq: clear stale request in tags->rq[] before freeing one request pool 2021-07-14 16:55:58 +02:00
blk-mq-virtio.c
blk-mq.c BACKPORT: FROMGIT: blk-mq: release crypto keyslot before reporting I/O complete 2023-03-29 20:05:47 +00:00
blk-mq.h blk-mq: grab rq->refcount before calling ->fn in blk_mq_tagset_busy_iter 2021-07-14 16:55:58 +02:00
blk-pm.c scsi: block: pm: Always set request queue runtime active in blk_post_runtime_resume() 2022-01-27 10:54:08 +01:00
blk-pm.h ANDROID: Revert "scsi: block: Do not accept any requests while suspended" 2021-07-13 10:52:35 -07:00
blk-rq-qos.c rq-qos: fix missed wake-ups in rq_qos_throttle try two 2021-07-19 09:45:00 +02:00
blk-rq-qos.h This is the 5.10.50 stable release 2021-07-14 17:35:23 +02:00
blk-settings.c Revert "BACKPORT: bio: limit bio max size" 2021-05-11 09:34:37 -07:00
blk-stat.c blk-stat: make q->stats->lock irqsafe 2020-09-01 16:48:46 -06:00
blk-stat.h
blk-sysfs.c block: don't delete queue kobject before its children 2022-04-08 14:40:00 +02:00
blk-throttle.c blk-throttle: prevent overflow while calculating wait time 2022-10-26 13:25:53 +02:00
blk-timeout.c block: blk-timeout: delete duplicated word 2020-07-31 16:29:47 -06:00
blk-wbt.c blk-wbt: fix that 'rwb->wc' is always set to 1 in wbt_init() 2022-10-30 09:41:19 +01:00
blk-wbt.h blk-wbt: introduce a new disable state to prevent false positive by rwb_enabled() 2021-07-14 16:56:12 +02:00
blk-zoned.c blk-zoned: allow BLKREPORTZONE without CAP_SYS_ADMIN 2021-09-18 13:40:06 +02:00
blk.h block: bump max plugged deferred size from 16 to 32 2021-11-18 14:03:57 +01:00
bounce.c block: make bio_crypt_clone() able to fail 2020-10-05 10:47:43 -06:00
bsg-lib.c block: drop double zeroing 2020-09-23 09:18:13 -06:00
bsg.c Merge 5.10.67 into android12-5.10-lts 2021-09-30 12:21:03 +02:00
cmdline-parser.c
elevator.c This is the 5.10.102 stable release 2022-02-23 12:56:37 +01:00
genhd.c block: Suppress uevent for hidden device when removed 2021-03-30 14:31:52 +02:00
ioctl.c block/compat_ioctl: fix range check in BLKGETSIZE 2022-04-27 13:53:57 +02:00
ioprio.c block: fix ioprio_get(IOPRIO_WHO_PGRP) vs setuid(2) 2021-12-14 11:32:40 +01:00
Kconfig FROMGIT: block: Introduce the ioprio rq-qos policy 2021-07-01 22:31:51 -07:00
Kconfig.iosched FROMGIT: block/mq-deadline: Add cgroup support 2021-07-01 22:31:54 -07:00
keyslot-manager.c UPSTREAM: block/keyslot-manager: introduce devm_blk_ksm_init() 2021-02-23 08:10:56 +01:00
kyber-iosched.c FROMGIT: blk-mq: Improve performance of non-mq IO schedulers with multiple HW queues 2021-07-01 22:31:49 -07:00
Makefile FROMGIT: block/mq-deadline: Add cgroup support 2021-07-01 22:31:54 -07:00
mq-deadline-cgroup.c FROMGIT: block/mq-deadline: Add cgroup support 2021-07-01 22:31:54 -07:00
mq-deadline-cgroup.h FROMGIT: block/mq-deadline: Add cgroup support 2021-07-01 22:31:54 -07:00
mq-deadline-main.c UPSTREAM: block/mq-deadline: Set the fifo_time member also if inserting at head 2022-11-16 14:48:59 +00:00
opal_proto.h
scsi_ioctl.c Revert "Revert "iov_iter: transparently handle compat iovecs in import_iovec"" 2020-11-02 09:27:36 +01:00
sed-opal.c block: sed-opal: kmalloc the cmd/resp buffers 2022-11-25 17:45:43 +01:00
t10-pi.c