[PATCH] media: dvb-core: bound section filter compare to the section buffer

From: Fabrice Derepas

Date: Wed Dec 02 2026 - 04:03:19 EST


dvb_dmx_swfilter_sectionfilter() always compares a fixed
DVB_DEMUX_MASK_MAX (18) bytes of the current section against the filter:

for (i = 0; i < DVB_DEMUX_MASK_MAX; i++)
... feed->feed.sec.secbuf[i] ...

secbuf points at secbuf_base + secbufp, so the loop reads
secbuf_base[secbufp .. secbufp + 17]. The section-dump loop in
dvb_dmx_swfilter_section_copy_dump() only guards the section body
(secbufp + 2 < limit, seclen + secbufp <= limit, limit <=
DMX_MAX_SECFEED_SIZE), and a section can be as short as 3 bytes. It
therefore admits secbufp up to DMX_MAX_SECFEED_SIZE - 3 (4281) with a
valid 3-byte section, while nothing bounds the fixed-width compare
against the end of secbuf_base[DMX_MAX_SECFEED_SIZE].

With a 3-byte section placed at secbufp = 4281, the compare reads
secbuf_base[4284 .. 4298] -- 15 bytes past the buffer and into the
members that follow secbuf_base[] in struct dmx_section_feed. On x86_64
those 15 bytes are secbufp/seclen/tsfeedp (6 bytes), 6 bytes of padding,
and the low 3 bytes of the set() function pointer. The read stays inside
the vmalloc'd feed array, so it does not fault.

The bytes read are compared against section-match positions 3..17,
which dvb_dmxdev_filter_start() fills from bytes 1..15 of the userspace
filter. A local process that both feeds the stream and sets the filter
can therefore tell from section delivery whether those bytes match a
value of its choosing, including the low 24 bits of a dvb-core function
pointer (of which the low 12 are a fixed page offset).

Clamp the number of compared bytes to what is left in the buffer. For
every section with at least DVB_DEMUX_MASK_MAX bytes before the buffer
end the behaviour is unchanged. For a short section starting in the last
17 bytes of the buffer the filter positions past the clamp are no longer
compared (they previously ran against the adjacent bytes), so such a
section that was dropped on a spurious mismatch may now be delivered.

Found with AWP (https://github.com/canonical/awp).

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Fabrice Derepas <fabrice.derepas@xxxxxxxxxxxxx>
---
This was first sent to security@xxxxxxxxxx, where it was judged not to
be a security issue and I was asked to handle it as a regular bug.

Compile-tested: drivers/media/dvb-core/dvb_demux.o builds clean against
base b6a9fa34ce41 (Linux 7.4-rc4) with CONFIG_DVB_CORE=y.

The out-of-bounds read was reproduced under clang AddressSanitizer on a
standalone user-space replica (the struct layout, the section-dump cursor
loop and the matcher), where secbuf_base[] is a separate allocation so the
index escape is caught: a 3-byte section at secbufp = 4281 faults one byte
past secbuf_base[] before the fix and is clean after, with the compare site
still covered. In the kernel the read runs past secbuf_base[] but stays
inside the vmalloc'd feed array, so KASAN would not flag it.

drivers/media/dvb-core/dvb_demux.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_demux.c b/drivers/media/dvb-core/dvb_demux.c
index 290fc7961..498d88836 100644
--- a/drivers/media/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb-core/dvb_demux.c
@@ -135,9 +135,16 @@ static int dvb_dmx_swfilter_sectionfilter(struct dvb_demux_feed *feed,
struct dvb_demux_filter *f)
{
u8 neq = 0;
- int i;
+ int i, n;
+
+ /*
+ * A short section can start near the end of secbuf_base[]; clamp the
+ * fixed-width compare so it never reads past the buffer.
+ */
+ n = min_t(int, DVB_DEMUX_MASK_MAX,
+ DMX_MAX_SECFEED_SIZE - feed->feed.sec.secbufp);

- for (i = 0; i < DVB_DEMUX_MASK_MAX; i++) {
+ for (i = 0; i < n; i++) {
u8 xor = f->filter.filter_value[i] ^ feed->feed.sec.secbuf[i];

if (f->maskandmode[i] & xor)

base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
--
2.53.0