From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796362590; b=Sn4ndVsGpAHM7YFL3DlVQgm35PVrBI7O0JtR1s4BqXGdGzZH6ht5Us7HpmdSriLGQ8r+ L9OLqiByRdZ4HZDcOSn1ewYHB0X0uVFSmxLGzZ7yDbIKxy01o/aR8/Jpu6OQcLvKsM/8M GqKhbrtsG7Dgy9naJulqWk+H+vpgkynXWFrZc4DZvxqCMztKLzHPVyacinrYwY7OfLqtT cfa0QkMM2GG3WONDPk3Zdl/UpDq6GQLv5gmdZXCP1TmRFwlsBqsx72cn6NJDyGqdUe71Q VcsI3tpFzSIHmlvAOdUrapC3pAlOq3pMe+Cp0DbQZKNozReci3rcYewEQPK+MxsqtRA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796362590; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bybGmtZ5ucOfwjMZ+2ExlxAlM2EMoSfbK8FmBJlYQ2M=; b=a47pZaVNeTDFuKWPwHaJlIGu9QaQxUEuCtxPF5yg12Z4AaoMePeMvoIcNXlD1KkAoGXr OOGnzhAG2btaq7YH2tTd//CWLYNkrRyWiYhc3GA8VehxlwyY+WtAEMXaSgYaJt6WzCXQq 3oDt7HjA4usGeU7Y7KDhX85C3IK+ZpoXWjlxkLPivQfyv1oeDx0dIIcik3TuSEpnz5JOd YiSPp4Eu8YlazwEab3HPCbYk57DxQV/HGPxv6Nr/oULqUIG5ptfU155exd3V7z3MAtPy2 L0ADOEb6qcyPhM8D6HheqFQ/EY9oXl7kepZCLniFp3SrlXfbojzu+fhGkWEeIfwrkrA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DytteRV9; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F474606A32C for ; Fri, 4 Dec 2026 05:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DytteRV9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 429BD1F000C2; Fri, 4 Dec 2026 05:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796362590; bh=bybGmtZ5ucOfwjMZ+2ExlxAlM2EMoSfbK8FmBJlYQ2M=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=DytteRV9mWB6ylnzUaNa5GvHbOWryFX8UnPPKq/1HD/Nq3a90+XZy/71MIdWVNQKD WGgt1gMky47hxZXTacSO2/5ZPWyzOh3DXmsLYRNSj+2hw41nvfvfQDMNxxhrnLV5dq ZeLLZZTHeRtdEZIoTmtQUJ4AwJFJzMcA/C/dHrpbOAoisZVwERx3FoyUU+ibNz1ZKK 7yfG1buVJ60GOH19gue5Ks2KOMVcc8tYTCw5tpbK2v8OrZ2BTJTN/SPrYLjpOfSwcw cdjvS4EdV/bMiGm+MCTTAEDZ+KPXlxQwnwNjeFqItuUufr7JPSwcSjH+TaUgb7gOkO Gsy/euRlqG72g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH v3 2/3] dm-verity: prevent FEC from publishing uninitialized hash blocks Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?5ZGo5Lyf5rGfIChXZWlqaWFuZyBaaG91KQ==?= , "Eric Biggers" , "Mikulas Patocka" Cc: =?utf-8?b?ZG0tZGV2ZWxAbGlzdHMubGludXguZGV2?= , =?utf-8?b?c2FtaXRvbHZhbmVuQGdvb2dsZS5jb20=?= , =?utf-8?b?YWdrQHJlZGhhdC5jb20=?= , =?utf-8?b?c25pdHpl?= =?utf-8?b?ckBrZXJuZWwub3Jn?= , =?utf-8?b?Ym1hcnpp?= =?utf-8?b?bnNAcmVkaGF0LmNvbQ==?= , =?utf-8?b?6YeR?= =?utf-8?b?57qi5a6HIChIb25neXUgSmluKQ==?= , =?utf-8?b?5ZC056Wl56aEIChYaWFuZ2x1IFd1KQ==?= , =?utf-8?b?5ZC05ZGo6ZWcIChKdXN0aW4gV3Up?= , =?utf-8?b?6IC/5oWI54aZIChDaXhpIEdlbmcvMTAwMzkp?= In-Reply-To: References: <5188c1e8-c08a-2a56-7e4c-1d84aba4df35@redhat.com> <179436615557.34024.8414792860115638345@unisoc.com> <20261113053639.GA76778@sol> <6b4ac19a42ce4297ae89ae0ae2fea674@zeshmbx08.spreadtrum.com> <20261202190429.GC338490@google.com> <35bcc428f6c0956f414a394d333e8e63@zeshmbx08.spreadtrum.com> <6e1ac631ecc44f41a38e8734cfffaca6@zeshmbx08.spreadtrum.com> <20261203184146.GC2267@sol> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 05:36:28 +0000 X-Mailing-List: dm-devel@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] dm-verity: pinned bad buffer across verity_fec_decode() blocks replacement - [Medium] dm-verity: FEC cache publish stalls on B_READING and evicts verified buffers - [Low] dm-bufio: dm_bufio_new_filled() doc falsely promises unconditional release - [Low] dm-verity: duplicated FEC cache publication logic in verity_verify_level() -- commit f5fba3aa170f055431dd1c64efc15af12f0b569d Author: =E5=91=A8=E4=BC=9F=E6=B1=9F (Weijiang Zhou) dm-verity: prevent FEC from publishing uninitialized hash blocks This commit changes verity_verify_level() to decode corrupted or unreadable metadata hash blocks into the per-I/O private FEC output buffer and publish the corrected block into dm-bufio via dm_bufio_new_filled(), rather than decoding into a cached buffer in place. > diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c > index 1906e487b20a5..12b5ff1b99ca8 100644 > --- a/drivers/md/dm-verity-target.c > +++ b/drivers/md/dm-verity-target.c > @@ -293,19 +293,42 @@ static int verity_verify_level(struct dm_verity *v,= struct dm_verity_io *io, [ ... ] > + u8 *output =3D verity_fec_output(io); > + > + dm_bufio_forget(v->bufio, hash_block); > + data =3D dm_bufio_new_filled(v->bufio, hash_block, > + output, &buf); > + if (IS_ERR(data)) { > + data =3D output; > + } else if (memcmp(data, output, > + 1 << v->hash_dev_block_bits)) { > + dm_bufio_release(buf); > + buf =3D NULL; > + data =3D output; > + } else { > aux =3D dm_bufio_get_aux_data(buf); > aux->hash_verified =3D 1; > - goto release_ok; > - } else { > - dm_bufio_release(buf); > - dm_bufio_forget(v->bufio, hash_block); > - return r; > } > + goto release_ok; [Severity: Medium] Can dm_bufio_forget() followed by dm_bufio_new_filled() stall an already-recovered worker on a concurrent failing read and leave the cache empty? When a read fails, new_read() removes the failed buffer on release. While one worker runs verity_fec_decode(), another reader can start a new failing read for the same block: CPU0 CPU1 dm_bufio_read_with_ioprio() -> err verity_fec_decode() ... dm_bufio_read_with_ioprio() inserts buf with B_READING dm_bufio_forget() <-- no-op (B_READING set) dm_bufio_new_filled() wait_on_bit_io(B_READING) <-- stalls on doomed read returns ERR_PTR(error) forget_buffer() skips eviction when B_READING is set, so dm_bufio_new_filled() -> new_read() blocks in TASK_UNINTERRUPTIBLE until the doomed bad-sector read fails and then returns ERR_PTR(error). The IS_ERR(data) fallback skips retrying publication, leaving the cache empty so later readers submit further failing reads and redundant FEC decodes. In addition, in both recovery branches, if one worker publishes and releases a verified buffer (b->state =3D=3D 0, hold_count =3D=3D 0), a seco= nd worker finishing FEC calls dm_bufio_forget() unconditionally and evicts that already-verified buffer, reopening a cache-miss window for fresh failing reads. [ ... ] > @@ -331,10 +354,38 @@ static int verity_verify_level(struct dm_verity *v,= struct dm_verity_io *io, > */ > r =3D -EAGAIN; > goto release_ret_r; > - } else if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_METADATA, > - want_digest, hash_block, data) =3D=3D 0) > - aux->hash_verified =3D 1; > - else if (verity_handle_err(v, > + } else if (verity_fec_decode(v, io, > + DM_VERITY_BLOCK_TYPE_METADATA, > + want_digest, hash_block, NULL) =3D=3D 0) { > + u8 *output =3D verity_fec_output(io); [ ... ] > + dm_bufio_release(buf); [Severity: Medium] Does holding buf across verity_fec_decode() prevent the corrupted buffer from being replaced under concurrent reads? fec_read_bufs() synchronously reads up to v->fec->rs_k blocks from storage before verity_fec_decode() returns, stretching the buffer hold window to tens or hundreds of milliseconds. Concurrent workers on v->verify_wq hitting the same corrupted hash block also pin buf across their own decodes, so when the first worker finishes, dm_bufio_release() leaves hold_count >=3D 1, dm_bufio_forget() -> cache_remove() refuses to evict it, and dm_bufio_new_filled() returns the same corrupted buffer. As long as reads touching that hash block arrive faster than a single FEC decode, hold_count never drops to zero, aux->hash_verified stays unset, and every arriving read triggers another full FEC decode storm. Releasing buf before calling verity_fec_decode() (saving the digest at data + offset if needed for DM_VERITY_MODE_LOGGING) narrows the hold window back to verity_hash(). > + dm_bufio_forget(v->bufio, hash_block); > + data =3D dm_bufio_new_filled(v->bufio, hash_block, > + output, &buf); > + if (IS_ERR(data)) { > + data =3D output; > + } else if (memcmp(data, output, > + 1 << v->hash_dev_block_bits)) { > + dm_bufio_release(buf); > + buf =3D NULL; > + data =3D output; > + } else { > + aux =3D dm_bufio_get_aux_data(buf); > + aux->hash_verified =3D 1; > + } > + goto release_ok; [Severity: Low] This isn't a bug, but the dm_bufio_forget() / dm_bufio_new_filled() publication and fallback sequence is duplicated verbatim between the I/O error and hash-mismatch branches, and the first branch declares u8 *output mid-block after executable statements. Extracting a small helper would remove both the duplication and the mid-block declaration. [ ... ] > @@ -351,7 +402,8 @@ static int verity_verify_level(struct dm_verity *v, s= truct dm_verity_io *io, > r =3D 0; > =20 > release_ret_r: > - dm_bufio_release(buf); > + if (buf) > + dm_bufio_release(buf); > return r; > } [Severity: Low] Does the comment on dm_bufio_new_filled() added in commit "dm-bufio: support atomic publication of pre-filled buffers" match dm_bufio_release()? That comment states that *bp is set to NULL on failure "so that callers can release unconditionally", but dm_bufio_release() immediately dereferences b->c without a NULL check and will NULL pointer dereference if a caller follows the comment literally. Since callers must guard cleanup with if (buf) as done here, the comment should reflect that requirement. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/f55322e3a71277d9274= 76ddb372064e0@zeshmbx08.spreadtrum.com?part=3D2