* [bug report] [media] mxb: fix audio handling
@ 2019-04-10 11:09 Dan Carpenter
2019-04-10 11:24 ` Hans Verkuil
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2019-04-10 11:09 UTC (permalink / raw)
To: hans.verkuil; +Cc: linux-media
[ Hi Hans,
This might not really be your bug, but I just respect you a lot and
so I always come to you with questions and for advice. -dan ]
Hello Hans Verkuil,
The patch 6680427791c9: "[media] mxb: fix audio handling" from Apr
30, 2012, leads to the following static checker warning:
drivers/media/pci/saa7146/mxb.c:196 tea6420_route()
warn: uncapped user index 'TEA6420_cd[idx]'
drivers/media/pci/saa7146/mxb.c
194 static inline void tea6420_route(struct mxb *mxb, int idx)
195 {
--> 196 v4l2_subdev_call(mxb->tea6420_1, audio, s_routing,
197 TEA6420_cd[idx][0].input, TEA6420_cd[idx][0].output, 0);
^^^
Index overflow. The TEA6420_cd[] array has MXB_AUDIOS + 1 (which is 7
altogether) elements.
198 v4l2_subdev_call(mxb->tea6420_2, audio, s_routing,
199 TEA6420_cd[idx][1].input, TEA6420_cd[idx][1].output, 0);
200 v4l2_subdev_call(mxb->tea6420_1, audio, s_routing,
201 TEA6420_line[idx][0].input, TEA6420_line[idx][0].output, 0);
202 v4l2_subdev_call(mxb->tea6420_2, audio, s_routing,
203 TEA6420_line[idx][1].input, TEA6420_line[idx][1].output, 0);
204 }
[ snip ]
650 static int vidioc_s_audio(struct file *file, void *fh, const struct v4l2_audio *a)
651 {
652 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
653 struct mxb *mxb = (struct mxb *)dev->ext_priv;
654
655 DEB_D("VIDIOC_S_AUDIO %d\n", a->index);
656 if (mxb_inputs[mxb->cur_input].audioset & (1 << a->index)) {
This a->index comes from the ioctl and it's a u32 so the shift can wrap.
The .audioset variable is always 0x3f. In other words BIT(6) is the
highest valid bit so we could add a check:
if (a->index > MXB_AUDIOS)
return;
657 if (mxb->cur_audinput != a->index) {
658 mxb->cur_audinput = a->index;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Now here's the complication. We also use a->index as an index into the
mxb_inputs[] array which only has MXB_INPUTS (4) elements, so just
adding the limit would still lead to a different array out of bounds
later...
659 tea6420_route(mxb, a->index);
660 if (mxb->cur_audinput == 0)
661 mxb_update_audmode(mxb);
662 }
663 return 0;
664 }
665 return -EINVAL;
666 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [bug report] [media] mxb: fix audio handling
2019-04-10 11:09 [bug report] [media] mxb: fix audio handling Dan Carpenter
@ 2019-04-10 11:24 ` Hans Verkuil
2019-04-10 11:39 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Hans Verkuil @ 2019-04-10 11:24 UTC (permalink / raw)
To: Dan Carpenter, hans.verkuil; +Cc: linux-media
On 4/10/19 1:09 PM, Dan Carpenter wrote:
> [ Hi Hans,
>
> This might not really be your bug, but I just respect you a lot and
> so I always come to you with questions and for advice. -dan ]
Hmm, in other words, I'm too nice!
>
> Hello Hans Verkuil,
>
> The patch 6680427791c9: "[media] mxb: fix audio handling" from Apr
> 30, 2012, leads to the following static checker warning:
>
> drivers/media/pci/saa7146/mxb.c:196 tea6420_route()
> warn: uncapped user index 'TEA6420_cd[idx]'
>
> drivers/media/pci/saa7146/mxb.c
> 194 static inline void tea6420_route(struct mxb *mxb, int idx)
> 195 {
> --> 196 v4l2_subdev_call(mxb->tea6420_1, audio, s_routing,
> 197 TEA6420_cd[idx][0].input, TEA6420_cd[idx][0].output, 0);
> ^^^
> Index overflow. The TEA6420_cd[] array has MXB_AUDIOS + 1 (which is 7
> altogether) elements.
>
> 198 v4l2_subdev_call(mxb->tea6420_2, audio, s_routing,
> 199 TEA6420_cd[idx][1].input, TEA6420_cd[idx][1].output, 0);
> 200 v4l2_subdev_call(mxb->tea6420_1, audio, s_routing,
> 201 TEA6420_line[idx][0].input, TEA6420_line[idx][0].output, 0);
> 202 v4l2_subdev_call(mxb->tea6420_2, audio, s_routing,
> 203 TEA6420_line[idx][1].input, TEA6420_line[idx][1].output, 0);
> 204 }
>
> [ snip ]
>
> 650 static int vidioc_s_audio(struct file *file, void *fh, const struct v4l2_audio *a)
> 651 {
> 652 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
> 653 struct mxb *mxb = (struct mxb *)dev->ext_priv;
> 654
> 655 DEB_D("VIDIOC_S_AUDIO %d\n", a->index);
> 656 if (mxb_inputs[mxb->cur_input].audioset & (1 << a->index)) {
>
> This a->index comes from the ioctl and it's a u32 so the shift can wrap.
> The .audioset variable is always 0x3f. In other words BIT(6) is the
> highest valid bit so we could add a check:
>
> if (a->index > MXB_AUDIOS)
> return;
That's correct.
>
> 657 if (mxb->cur_audinput != a->index) {
> 658 mxb->cur_audinput = a->index;
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Now here's the complication. We also use a->index as an index into the
> mxb_inputs[] array which only has MXB_INPUTS (4) elements, so just
We do? Where does that happen? I don't see that in the code. That would be
a bug since mxb_inputs are the video inputs, whereas s_audio deals with
audio inputs.
Regards,
Hans
> adding the limit would still lead to a different array out of bounds
> later...
>
> 659 tea6420_route(mxb, a->index);
> 660 if (mxb->cur_audinput == 0)
> 661 mxb_update_audmode(mxb);
> 662 }
> 663 return 0;
> 664 }
> 665 return -EINVAL;
> 666 }
>
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [bug report] [media] mxb: fix audio handling
2019-04-10 11:24 ` Hans Verkuil
@ 2019-04-10 11:39 ` Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2019-04-10 11:39 UTC (permalink / raw)
To: Hans Verkuil; +Cc: hans.verkuil, linux-media
On Wed, Apr 10, 2019 at 01:24:44PM +0200, Hans Verkuil wrote:
> On 4/10/19 1:09 PM, Dan Carpenter wrote:
> > [ Hi Hans,
> >
> > This might not really be your bug, but I just respect you a lot and
> > so I always come to you with questions and for advice. -dan ]
>
> Hmm, in other words, I'm too nice!
>
Indeed.
> > 657 if (mxb->cur_audinput != a->index) {
> > 658 mxb->cur_audinput = a->index;
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > Now here's the complication. We also use a->index as an index into the
> > mxb_inputs[] array which only has MXB_INPUTS (4) elements, so just
>
> We do? Where does that happen? I don't see that in the code. That would be
> a bug since mxb_inputs are the video inputs, whereas s_audio deals with
> audio inputs.
>
Oh, you're right. But then there is a smaller problem because we use
it as in index into the mxb_audios[] array and that array only has 6
elements so we're still out of bounds. The bigger array has a mute
element at the end.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-10 11:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-10 11:09 [bug report] [media] mxb: fix audio handling Dan Carpenter
2019-04-10 11:24 ` Hans Verkuil
2019-04-10 11:39 ` Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.