Skip to content

block/linux-aio: fix reproducible SIGSEGV from unbounded ioq_submit() recursion

Denis V. Lunev via qemu development qemu-devel 3 versions – Applied

Status from this message: Thanks, applied to my block tree:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest0 of 1 patch 1 replyApplied
  2. v20 of 1 patch 0 repliesSuperseded
  3. v11 patch 0 repliesSuperseded

Changes in v3 from the cover letter

* moved depth guard to struct qemu_laiocb (suggestion from Stefan)

Patches in v3 Applied

The patch the cover letter announces is not in this archive.

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/1] block/linux-aio: fix reproducible SIGSEGV from unbounded ioq_submit() recursion

Observed in production where a cached-I/O backup path was driven through aio=native, making io_submit(2) complete synchronously and closing the recursion cycle. On the supported aio=native + cache=none
+ qcow2 configuration the cycle stays bounded by accident rather than by construction; this patch bounds it explicitly.

Bisect:

  v8.1.0 (forward edge only)      no crash / 20
  84d61e5f36^                     no crash / 20
  84d61e5f36 (backward edge in)   crash at attempt 17
  v8.2.0                          crash at attempt  4
  master + this patch             no crash / 80

The closing commit is 84d61e5f36 ("virtio: use defer_call() in virtio_irqfd_notify()").

No iotest: crash rate is 6..17 per 20 on unpatched master; a formal test would be flaky. The vmdk + aio=native + cache=none shape is not otherwise exercised by the suite.

--- gen-workload.py ----------------------------------------------- #!/usr/bin/env python3
import random, sys
REGION = 32 * 1024 * 1024
CLUSTER = 64 * 1024
SEED = 0xC0FFEE
def main(out):

    r = random.Random(SEED); ops = []
    for _ in range(10000):
        off = r.randrange(0, REGION - 4096) & ~4095
        ops.append("aio_write -q %d 4k" % off)
    for i in range(10000):
        size, n = ("64k", 65536) if i < 5000 else ("128k", 131072)
        off = r.randrange(0, REGION - n) & ~(CLUSTER - 1)
        ops.append("aio_write -q -z -u %d %s" % (off, size))
    r.shuffle(ops); ops.append("aio_flush")
    open(out, "w").write("\n".join(ops) + "\n")
if __name__ == "__main__":
    main(sys.argv[1] if len(sys.argv) > 1 else "t.cmds")

-------------------------------------------------------------------

--- repro.sh ------------------------------------------------------ #!/bin/bash
set -u
qimg=$1; qio=$2; label=$3; attempts=${4:-20} cmds=${5:-$(dirname "$0")/t.cmds} vmdk=/tmp/t.$label.vmdk; log=/tmp/repro_$label.log
: > "$log"
for i in $(seq 1 "$attempts"); do

    rm -f "$vmdk"
    "$qimg" create -f vmdk "$vmdk" 256M >/dev/null 2>&1
    "$qio" -f vmdk -n --cache=none --aio=native "$vmdk" < "$cmds" \
        >>"$log" 2>&1
    rc=$?
    [ $rc -ge 128 ] && { echo "CRASH attempt $i rc=$rc" >>"$log"; break; }

done
echo "DONE $label rc=$rc attempt=$i" >> "$log"
-------------------------------------------------------------------

python3 gen-workload.py t.cmds
./repro.sh /path/to/qemu-img /path/to/qemu-io test 20

Notes:

* IOQ_SUBMIT_MAX_DEPTH = 8. Round headroom over the bounded depth of the supported async-completion path.
* Per-thread __thread counter, matching util/defer-call.c's storage. A per-LinuxAioState field would let multiple devices on one thread recurse independently.

Changes from v2:
* moved depth guard to struct qemu_laiocb (suggestion from Stefan)

Changes from v1:
* removed all downstream marks

Denis V. Lunev (1):
block/linux-aio: bound ioq_submit() recursion depth

 block/linux-aio.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
CC Kevin Wolf <[email protected]>
CC Hanna Reitz <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Paolo Bonzini <[email protected]>

--
2.51.0