aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/firewire/firedtv-ci.c
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2021-06-07 17:23:48 +0200
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>2021-09-30 10:07:54 +0200
commit35d2969ea3c7d32aee78066b1f3cf61a0d935a4e (patch)
tree6351503e6a1eaf3c45090e352479afeb83f8a3c5 /drivers/media/firewire/firedtv-ci.c
parent9031d6b3623f12e7aac6b5f3690ce575a4557da7 (diff)
downloadlinux-35d2969ea3c7d32aee78066b1f3cf61a0d935a4e.tar.gz
media: firewire: firedtv-avc: fix a buffer overflow in avc_ca_pmt()
The bounds checking in avc_ca_pmt() is not strict enough. It should be checking "read_pos + 4" because it's reading 5 bytes. If the "es_info_length" is non-zero then it reads a 6th byte so there needs to be an additional check for that. I also added checks for the "write_pos". I don't think these are required because "read_pos" and "write_pos" are tied together so checking one ought to be enough. But they make the code easier to understand for me. The check on write_pos is: if (write_pos + 4 >= sizeof(c->operand) - 4) { The first "+ 4" is because we're writing 5 bytes and the last " - 4" is to leave space for the CRC. The other problem is that "length" can be invalid. It comes from "data_length" in fdtv_ca_pmt(). Cc: stable@vger.kernel.org Reported-by: Luo Likang <luolikang@nsfocus.com> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Diffstat (limited to 'drivers/media/firewire/firedtv-ci.c')
-rw-r--r--drivers/media/firewire/firedtv-ci.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/media/firewire/firedtv-ci.c b/drivers/media/firewire/firedtv-ci.c
index 9363d005e2b6..e0d57e09dab0 100644
--- a/drivers/media/firewire/firedtv-ci.c
+++ b/drivers/media/firewire/firedtv-ci.c
@@ -134,6 +134,8 @@ static int fdtv_ca_pmt(struct firedtv *fdtv, void *arg)
} else {
data_length = msg->msg[3];
}
+ if (data_length > sizeof(msg->msg) - data_pos)
+ return -EINVAL;
return avc_ca_pmt(fdtv, &msg->msg[data_pos], data_length);
}