* [PATCH] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() @ 2021-11-30 16:12 Zhou Qingyang 2021-12-01 8:41 ` Dan Carpenter 0 siblings, 1 reply; 9+ messages in thread From: Zhou Qingyang @ 2021-11-30 16:12 UTC (permalink / raw) To: zhou1615 Cc: kjlu, Neil Armstrong, Mauro Carvalho Chehab, Greg Kroah-Hartman, Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Hans Verkuil, Maxime Jourdan, linux-media, linux-amlogic, linux-staging, linux-arm-kernel, linux-kernel In amvdec_add_ts(), there is a dereference of kzalloc(), which could lead to a NULL pointer dereference on failure of kzalloc(). I fix this bug by adding a NULL check of new_ts. This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_VIDEO_MESON_VDEC=m show no new warnings, and our static analyzer no longer warns about this code. Fixes: 876f123b8956 ("media: meson: vdec: bring up to compliance") Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> --- drivers/staging/media/meson/vdec/vdec_helpers.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c index b9125c295d1d..41297c2f8f9a 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.c +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c @@ -234,6 +234,11 @@ void amvdec_add_ts(struct amvdec_session *sess, u64 ts, unsigned long flags; new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL); + if (!new_ts) { + dev_err(sess->core->dev_dec, + "No enough memory in %s\n", __func__); + return; + } new_ts->ts = ts; new_ts->tc = tc; new_ts->offset = offset; -- 2.25.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() 2021-11-30 16:12 [PATCH] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() Zhou Qingyang @ 2021-12-01 8:41 ` Dan Carpenter 2021-12-02 16:03 ` [PATCH v2] " Zhou Qingyang 0 siblings, 1 reply; 9+ messages in thread From: Dan Carpenter @ 2021-12-01 8:41 UTC (permalink / raw) To: Zhou Qingyang Cc: kjlu, Neil Armstrong, Mauro Carvalho Chehab, Greg Kroah-Hartman, Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Hans Verkuil, Maxime Jourdan, linux-media, linux-amlogic, linux-staging, linux-arm-kernel, linux-kernel On Wed, Dec 01, 2021 at 12:12:23AM +0800, Zhou Qingyang wrote: > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c > index b9125c295d1d..41297c2f8f9a 100644 > --- a/drivers/staging/media/meson/vdec/vdec_helpers.c > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c > @@ -234,6 +234,11 @@ void amvdec_add_ts(struct amvdec_session *sess, u64 ts, > unsigned long flags; > > new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL); > + if (!new_ts) { > + dev_err(sess->core->dev_dec, > + "No enough memory in %s\n", __func__); > + return; Please run checkpatch.pl on your patches. The dev_err() message should be deleted because kzalloc() already has a better message built in. WARNING: Possible unnecessary 'out of memory' message #50: FILE: drivers/staging/media/meson/vdec/vdec_helpers.c:238: + if (!new_ts) { + dev_err(sess->core->dev_dec, regards, dan carpenter ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() 2021-12-01 8:41 ` Dan Carpenter @ 2021-12-02 16:03 ` Zhou Qingyang 2021-12-03 13:30 ` Dan Carpenter 2021-12-14 13:46 ` Mauro Carvalho Chehab 0 siblings, 2 replies; 9+ messages in thread From: Zhou Qingyang @ 2021-12-02 16:03 UTC (permalink / raw) To: zhou1615 Cc: kjlu, Neil Armstrong, Mauro Carvalho Chehab, Greg Kroah-Hartman, Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Hans Verkuil, Maxime Jourdan, linux-media, linux-amlogic, linux-staging, linux-arm-kernel, linux-kernel In amvdec_add_ts(), there is a dereference of kzalloc(), which could lead to a NULL pointer dereference on failure of kzalloc(). I fix this bug by adding a NULL check of new_ts. This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_VIDEO_MESON_VDEC=m show no new warnings, and our static analyzer no longer warns about this code. Fixes: 876f123b8956 ("media: meson: vdec: bring up to compliance") Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> --- Changes in v2: - Delete dev_err() message drivers/staging/media/meson/vdec/vdec_helpers.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c index b9125c295d1d..ac60514c475b 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.c +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c @@ -234,6 +234,9 @@ void amvdec_add_ts(struct amvdec_session *sess, u64 ts, unsigned long flags; new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL); + if (!new_ts) + return; + new_ts->ts = ts; new_ts->tc = tc; new_ts->offset = offset; -- 2.25.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() 2021-12-02 16:03 ` [PATCH v2] " Zhou Qingyang @ 2021-12-03 13:30 ` Dan Carpenter 2021-12-14 13:46 ` Mauro Carvalho Chehab 1 sibling, 0 replies; 9+ messages in thread From: Dan Carpenter @ 2021-12-03 13:30 UTC (permalink / raw) To: Zhou Qingyang Cc: kjlu, Neil Armstrong, Mauro Carvalho Chehab, Greg Kroah-Hartman, Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Hans Verkuil, Maxime Jourdan, linux-media, linux-amlogic, linux-staging, linux-arm-kernel, linux-kernel On Fri, Dec 03, 2021 at 12:03:57AM +0800, Zhou Qingyang wrote: > In amvdec_add_ts(), there is a dereference of kzalloc(), which could lead > to a NULL pointer dereference on failure of kzalloc(). > > I fix this bug by adding a NULL check of new_ts. > > This bug was found by a static analyzer. The analysis employs > differential checking to identify inconsistent security operations > (e.g., checks or kfrees) between two code paths and confirms that the > inconsistent operations are not recovered in the current function or > the callers, so they constitute bugs. > > Note that, as a bug found by static analysis, it can be a false > positive or hard to trigger. Multiple researchers have cross-reviewed > the bug. > > Builds with CONFIG_VIDEO_MESON_VDEC=m show no new warnings, > and our static analyzer no longer warns about this code. > > Fixes: 876f123b8956 ("media: meson: vdec: bring up to compliance") > Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> > --- ^^^ Thanks. Next time put the meta commentary about how the bug was found and the QC process under the the --- cut off line. We don't need to have that drama stored in the permanent git log. Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com> regards, dan carpenter ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() 2021-12-02 16:03 ` [PATCH v2] " Zhou Qingyang 2021-12-03 13:30 ` Dan Carpenter @ 2021-12-14 13:46 ` Mauro Carvalho Chehab 2021-12-14 14:16 ` Greg Kroah-Hartman 2021-12-15 3:35 ` [PATCH v3] " Zhou Qingyang 1 sibling, 2 replies; 9+ messages in thread From: Mauro Carvalho Chehab @ 2021-12-14 13:46 UTC (permalink / raw) To: Zhou Qingyang Cc: kjlu, Neil Armstrong, Greg Kroah-Hartman, Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Hans Verkuil, Maxime Jourdan, linux-media, linux-amlogic, linux-staging, linux-arm-kernel, linux-kernel Em Fri, 3 Dec 2021 00:03:57 +0800 Zhou Qingyang <zhou1615@umn.edu> escreveu: > In amvdec_add_ts(), there is a dereference of kzalloc(), which could lead > to a NULL pointer dereference on failure of kzalloc(). > > I fix this bug by adding a NULL check of new_ts. > > This bug was found by a static analyzer. The analysis employs > differential checking to identify inconsistent security operations > (e.g., checks or kfrees) between two code paths and confirms that the > inconsistent operations are not recovered in the current function or > the callers, so they constitute bugs. > > Note that, as a bug found by static analysis, it can be a false > positive or hard to trigger. Multiple researchers have cross-reviewed > the bug. > > Builds with CONFIG_VIDEO_MESON_VDEC=m show no new warnings, > and our static analyzer no longer warns about this code. > > Fixes: 876f123b8956 ("media: meson: vdec: bring up to compliance") > Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> > --- > Changes in v2: > - Delete dev_err() message > > drivers/staging/media/meson/vdec/vdec_helpers.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c > index b9125c295d1d..ac60514c475b 100644 > --- a/drivers/staging/media/meson/vdec/vdec_helpers.c > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c > @@ -234,6 +234,9 @@ void amvdec_add_ts(struct amvdec_session *sess, u64 ts, > unsigned long flags; > > new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL); > + if (!new_ts) > + return; > + > new_ts->ts = ts; > new_ts->tc = tc; > new_ts->offset = offset; I don't think this change is ok. Sure, it needs to check if kzalloc() fails, but it should return -ENOMEM and the caller should check if it returns an error. So, I would expect that this patch would also touch the caller function at drivers/staging/media/meson/vdec/esparser.c. Regards, Mauro Thanks, Mauro ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() 2021-12-14 13:46 ` Mauro Carvalho Chehab @ 2021-12-14 14:16 ` Greg Kroah-Hartman 2021-12-15 3:35 ` [PATCH v3] " Zhou Qingyang 1 sibling, 0 replies; 9+ messages in thread From: Greg Kroah-Hartman @ 2021-12-14 14:16 UTC (permalink / raw) To: Mauro Carvalho Chehab Cc: Zhou Qingyang, kjlu, Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Hans Verkuil, Maxime Jourdan, linux-media, linux-amlogic, linux-staging, linux-arm-kernel, linux-kernel On Tue, Dec 14, 2021 at 02:46:13PM +0100, Mauro Carvalho Chehab wrote: > Em Fri, 3 Dec 2021 00:03:57 +0800 > Zhou Qingyang <zhou1615@umn.edu> escreveu: > > > In amvdec_add_ts(), there is a dereference of kzalloc(), which could lead > > to a NULL pointer dereference on failure of kzalloc(). > > > > I fix this bug by adding a NULL check of new_ts. > > > > This bug was found by a static analyzer. The analysis employs > > differential checking to identify inconsistent security operations > > (e.g., checks or kfrees) between two code paths and confirms that the > > inconsistent operations are not recovered in the current function or > > the callers, so they constitute bugs. > > > > Note that, as a bug found by static analysis, it can be a false > > positive or hard to trigger. Multiple researchers have cross-reviewed > > the bug. > > > > Builds with CONFIG_VIDEO_MESON_VDEC=m show no new warnings, > > and our static analyzer no longer warns about this code. > > > > Fixes: 876f123b8956 ("media: meson: vdec: bring up to compliance") > > Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> > > --- > > Changes in v2: > > - Delete dev_err() message > > > > drivers/staging/media/meson/vdec/vdec_helpers.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c > > index b9125c295d1d..ac60514c475b 100644 > > --- a/drivers/staging/media/meson/vdec/vdec_helpers.c > > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c > > @@ -234,6 +234,9 @@ void amvdec_add_ts(struct amvdec_session *sess, u64 ts, > > unsigned long flags; > > > > new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL); > > + if (!new_ts) > > + return; > > + > > new_ts->ts = ts; > > new_ts->tc = tc; > > new_ts->offset = offset; > > I don't think this change is ok. Sure, it needs to check if > kzalloc() fails, but it should return -ENOMEM and the caller > should check if it returns an error. So, I would expect > that this patch would also touch the caller function at > drivers/staging/media/meson/vdec/esparser.c. This is why umn.edu emails still are in my black-hole :( ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() 2021-12-14 13:46 ` Mauro Carvalho Chehab 2021-12-14 14:16 ` Greg Kroah-Hartman @ 2021-12-15 3:35 ` Zhou Qingyang 2022-01-11 9:16 ` Hans Verkuil 1 sibling, 1 reply; 9+ messages in thread From: Zhou Qingyang @ 2021-12-15 3:35 UTC (permalink / raw) To: zhou1615 Cc: kjlu, Neil Armstrong, Mauro Carvalho Chehab, Greg Kroah-Hartman, Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Maxime Jourdan, Hans Verkuil, linux-media, linux-amlogic, linux-staging, linux-arm-kernel, linux-kernel In amvdec_add_ts(), there is a dereference of kzalloc(), which could lead to a NULL pointer dereference on failure of kzalloc(). Fix this bug by adding a NULL check of new_ts. This bug was found by a static analyzer[1]. Builds with CONFIG_VIDEO_MESON_VDEC=m show no new warnings, and our static analyzer no longer warns about this code. Fixes: 876f123b8956 ("media: meson: vdec: bring up to compliance") Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> --- [1] The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Changes in v3: - Change the description of patch - Turn the return type from 'void' to 'int' - Check the return value in the caller 'esparser_queue()' Changes in v2: - Delete dev_err() message drivers/staging/media/meson/vdec/esparser.c | 7 ++++++- drivers/staging/media/meson/vdec/vdec_helpers.c | 8 ++++++-- drivers/staging/media/meson/vdec/vdec_helpers.h | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/staging/media/meson/vdec/esparser.c b/drivers/staging/media/meson/vdec/esparser.c index db7022707ff8..095100a50da8 100644 --- a/drivers/staging/media/meson/vdec/esparser.c +++ b/drivers/staging/media/meson/vdec/esparser.c @@ -328,7 +328,12 @@ esparser_queue(struct amvdec_session *sess, struct vb2_v4l2_buffer *vbuf) offset = esparser_get_offset(sess); - amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags); + ret = amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags); + if (!ret) { + v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR); + return ret; + } + dev_dbg(core->dev, "esparser: ts = %llu pld_size = %u offset = %08X flags = %08X\n", vb->timestamp, payload_size, offset, vbuf->flags); diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c index b9125c295d1d..06fd66539797 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.c +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c @@ -227,13 +227,16 @@ int amvdec_set_canvases(struct amvdec_session *sess, } EXPORT_SYMBOL_GPL(amvdec_set_canvases); -void amvdec_add_ts(struct amvdec_session *sess, u64 ts, - struct v4l2_timecode tc, u32 offset, u32 vbuf_flags) +int amvdec_add_ts(struct amvdec_session *sess, u64 ts, + struct v4l2_timecode tc, u32 offset, u32 vbuf_flags) { struct amvdec_timestamp *new_ts; unsigned long flags; new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL); + if (!new_ts) + return -ENOMEM; + new_ts->ts = ts; new_ts->tc = tc; new_ts->offset = offset; @@ -242,6 +245,7 @@ void amvdec_add_ts(struct amvdec_session *sess, u64 ts, spin_lock_irqsave(&sess->ts_spinlock, flags); list_add_tail(&new_ts->list, &sess->timestamps); spin_unlock_irqrestore(&sess->ts_spinlock, flags); + return 0; } EXPORT_SYMBOL_GPL(amvdec_add_ts); diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.h b/drivers/staging/media/meson/vdec/vdec_helpers.h index 88137d15aa3a..4bf3e61d081b 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.h +++ b/drivers/staging/media/meson/vdec/vdec_helpers.h @@ -56,8 +56,8 @@ void amvdec_dst_buf_done_offset(struct amvdec_session *sess, * @offset: offset in the VIFIFO where the associated packet was written * @flags: the vb2_v4l2_buffer flags */ -void amvdec_add_ts(struct amvdec_session *sess, u64 ts, - struct v4l2_timecode tc, u32 offset, u32 flags); +int amvdec_add_ts(struct amvdec_session *sess, u64 ts, + struct v4l2_timecode tc, u32 offset, u32 flags); void amvdec_remove_ts(struct amvdec_session *sess, u64 ts); /** -- 2.25.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() 2021-12-15 3:35 ` [PATCH v3] " Zhou Qingyang @ 2022-01-11 9:16 ` Hans Verkuil [not found] ` <CA+Cm_xSOv5NnW5GXcKKGi8bQSvT45iH6=65YJk3EG6uW0c5_Vw@mail.gmail.com> 0 siblings, 1 reply; 9+ messages in thread From: Hans Verkuil @ 2022-01-11 9:16 UTC (permalink / raw) To: Zhou Qingyang, Neil Armstrong Cc: kjlu, Mauro Carvalho Chehab, Greg Kroah-Hartman, Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Maxime Jourdan, linux-media, linux-amlogic, linux-staging, linux-arm-kernel, linux-kernel Zhou Qingyang, this is exactly the patch Neil wrote, except you just stuck your name on it. Not nice. Neil, can you post your patch with your own Signed-off-by, then I'll take that one. Regards, Hans On 15/12/2021 04:35, Zhou Qingyang wrote: > In amvdec_add_ts(), there is a dereference of kzalloc(), which could lead > to a NULL pointer dereference on failure of kzalloc(). > > Fix this bug by adding a NULL check of new_ts. > > This bug was found by a static analyzer[1]. > > Builds with CONFIG_VIDEO_MESON_VDEC=m show no new warnings, > and our static analyzer no longer warns about this code. > > Fixes: 876f123b8956 ("media: meson: vdec: bring up to compliance") > Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> > --- > > [1] The analysis employs differential checking to identify inconsistent > security operations (e.g., checks or kfrees) between two code paths and > confirms that the inconsistent operations are not recovered in the > current function or the callers, so they constitute bugs. > > Note that, as a bug found by static analysis, it can be a false > positive or hard to trigger. Multiple researchers have cross-reviewed > the bug. > > Changes in v3: > - Change the description of patch > - Turn the return type from 'void' to 'int' > - Check the return value in the caller 'esparser_queue()' > > Changes in v2: > - Delete dev_err() message > > drivers/staging/media/meson/vdec/esparser.c | 7 ++++++- > drivers/staging/media/meson/vdec/vdec_helpers.c | 8 ++++++-- > drivers/staging/media/meson/vdec/vdec_helpers.h | 4 ++-- > 3 files changed, 14 insertions(+), 5 deletions(-) > > diff --git a/drivers/staging/media/meson/vdec/esparser.c b/drivers/staging/media/meson/vdec/esparser.c > index db7022707ff8..095100a50da8 100644 > --- a/drivers/staging/media/meson/vdec/esparser.c > +++ b/drivers/staging/media/meson/vdec/esparser.c > @@ -328,7 +328,12 @@ esparser_queue(struct amvdec_session *sess, struct vb2_v4l2_buffer *vbuf) > > offset = esparser_get_offset(sess); > > - amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags); > + ret = amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags); > + if (!ret) { > + v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR); > + return ret; > + } > + > dev_dbg(core->dev, "esparser: ts = %llu pld_size = %u offset = %08X flags = %08X\n", > vb->timestamp, payload_size, offset, vbuf->flags); > > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c > index b9125c295d1d..06fd66539797 100644 > --- a/drivers/staging/media/meson/vdec/vdec_helpers.c > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c > @@ -227,13 +227,16 @@ int amvdec_set_canvases(struct amvdec_session *sess, > } > EXPORT_SYMBOL_GPL(amvdec_set_canvases); > > -void amvdec_add_ts(struct amvdec_session *sess, u64 ts, > - struct v4l2_timecode tc, u32 offset, u32 vbuf_flags) > +int amvdec_add_ts(struct amvdec_session *sess, u64 ts, > + struct v4l2_timecode tc, u32 offset, u32 vbuf_flags) > { > struct amvdec_timestamp *new_ts; > unsigned long flags; > > new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL); > + if (!new_ts) > + return -ENOMEM; > + > new_ts->ts = ts; > new_ts->tc = tc; > new_ts->offset = offset; > @@ -242,6 +245,7 @@ void amvdec_add_ts(struct amvdec_session *sess, u64 ts, > spin_lock_irqsave(&sess->ts_spinlock, flags); > list_add_tail(&new_ts->list, &sess->timestamps); > spin_unlock_irqrestore(&sess->ts_spinlock, flags); > + return 0; > } > EXPORT_SYMBOL_GPL(amvdec_add_ts); > > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.h b/drivers/staging/media/meson/vdec/vdec_helpers.h > index 88137d15aa3a..4bf3e61d081b 100644 > --- a/drivers/staging/media/meson/vdec/vdec_helpers.h > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.h > @@ -56,8 +56,8 @@ void amvdec_dst_buf_done_offset(struct amvdec_session *sess, > * @offset: offset in the VIFIFO where the associated packet was written > * @flags: the vb2_v4l2_buffer flags > */ > -void amvdec_add_ts(struct amvdec_session *sess, u64 ts, > - struct v4l2_timecode tc, u32 offset, u32 flags); > +int amvdec_add_ts(struct amvdec_session *sess, u64 ts, > + struct v4l2_timecode tc, u32 offset, u32 flags); > void amvdec_remove_ts(struct amvdec_session *sess, u64 ts); > > /** ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <CA+Cm_xSOv5NnW5GXcKKGi8bQSvT45iH6=65YJk3EG6uW0c5_Vw@mail.gmail.com>]
* Re: [PATCH v3] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() [not found] ` <CA+Cm_xSOv5NnW5GXcKKGi8bQSvT45iH6=65YJk3EG6uW0c5_Vw@mail.gmail.com> @ 2022-01-12 8:57 ` Neil Armstrong 0 siblings, 0 replies; 9+ messages in thread From: Neil Armstrong @ 2022-01-12 8:57 UTC (permalink / raw) To: Qingyang Zhou, Hans Verkuil Cc: Kangjie Lu, Mauro Carvalho Chehab, Greg Kroah-Hartman, Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Maxime Jourdan, linux-media, linux-amlogic, linux-staging, linux-arm-kernel, linux-kernel Hi, On 11/01/2022 14:03, Qingyang Zhou wrote: > Hi Hans: > > Here I certify that this is an origin patch I wrote. I did not copy Neil's patch, and I did not know his patch. > > Neil, please post your original patch here, so everyone can see both patches. > > Yours > Zhou Qingyang. > > On Tue, Jan 11, 2022 at 5:16 PM Hans Verkuil <hverkuil-cisco@xs4all.nl <mailto:hverkuil-cisco@xs4all.nl>> wrote: > > Zhou Qingyang, this is exactly the patch Neil wrote, except you just stuck your > name on it. Not nice. > > Neil, can you post your patch with your own Signed-off-by, then I'll take that one. > > Regards, > > Hans > > On 15/12/2021 04:35, Zhou Qingyang wrote: > > In amvdec_add_ts(), there is a dereference of kzalloc(), which could lead > > to a NULL pointer dereference on failure of kzalloc(). > > > > Fix this bug by adding a NULL check of new_ts. > > > > This bug was found by a static analyzer[1]. > > > > Builds with CONFIG_VIDEO_MESON_VDEC=m show no new warnings, > > and our static analyzer no longer warns about this code. > > > > Fixes: 876f123b8956 ("media: meson: vdec: bring up to compliance") > > Signed-off-by: Zhou Qingyang <zhou1615@umn.edu <mailto:zhou1615@umn.edu>> > > --- > > > > [1] The analysis employs differential checking to identify inconsistent > > security operations (e.g., checks or kfrees) between two code paths and > > confirms that the inconsistent operations are not recovered in the > > current function or the callers, so they constitute bugs. > > > > Note that, as a bug found by static analysis, it can be a false > > positive or hard to trigger. Multiple researchers have cross-reviewed > > the bug. > > > > Changes in v3: > > - Change the description of patch > > - Turn the return type from 'void' to 'int' > > - Check the return value in the caller 'esparser_queue()' > > > > Changes in v2: > > - Delete dev_err() message > > > > drivers/staging/media/meson/vdec/esparser.c | 7 ++++++- > > drivers/staging/media/meson/vdec/vdec_helpers.c | 8 ++++++-- > > drivers/staging/media/meson/vdec/vdec_helpers.h | 4 ++-- > > 3 files changed, 14 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/staging/media/meson/vdec/esparser.c b/drivers/staging/media/meson/vdec/esparser.c > > index db7022707ff8..095100a50da8 100644 > > --- a/drivers/staging/media/meson/vdec/esparser.c > > +++ b/drivers/staging/media/meson/vdec/esparser.c > > @@ -328,7 +328,12 @@ esparser_queue(struct amvdec_session *sess, struct vb2_v4l2_buffer *vbuf) > > > > offset = esparser_get_offset(sess); > > > > - amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags); > > + ret = amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags); > > + if (!ret) { > > + v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR); > > + return ret; > > + } > > + > > dev_dbg(core->dev, "esparser: ts = %llu pld_size = %u offset = %08X flags = %08X\n", > > vb->timestamp, payload_size, offset, vbuf->flags); > > > > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c > > index b9125c295d1d..06fd66539797 100644 > > --- a/drivers/staging/media/meson/vdec/vdec_helpers.c > > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c > > @@ -227,13 +227,16 @@ int amvdec_set_canvases(struct amvdec_session *sess, > > } > > EXPORT_SYMBOL_GPL(amvdec_set_canvases); > > > > -void amvdec_add_ts(struct amvdec_session *sess, u64 ts, > > - struct v4l2_timecode tc, u32 offset, u32 vbuf_flags) > > +int amvdec_add_ts(struct amvdec_session *sess, u64 ts, > > + struct v4l2_timecode tc, u32 offset, u32 vbuf_flags) > > { > > struct amvdec_timestamp *new_ts; > > unsigned long flags; > > > > new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL); > > + if (!new_ts) > > + return -ENOMEM; > > + > > new_ts->ts = ts; > > new_ts->tc = tc; > > new_ts->offset = offset; > > @@ -242,6 +245,7 @@ void amvdec_add_ts(struct amvdec_session *sess, u64 ts, > > spin_lock_irqsave(&sess->ts_spinlock, flags); > > list_add_tail(&new_ts->list, &sess->timestamps); > > spin_unlock_irqrestore(&sess->ts_spinlock, flags); > > + return 0; > > } > > EXPORT_SYMBOL_GPL(amvdec_add_ts); > > > > diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.h b/drivers/staging/media/meson/vdec/vdec_helpers.h > > index 88137d15aa3a..4bf3e61d081b 100644 > > --- a/drivers/staging/media/meson/vdec/vdec_helpers.h > > +++ b/drivers/staging/media/meson/vdec/vdec_helpers.h > > @@ -56,8 +56,8 @@ void amvdec_dst_buf_done_offset(struct amvdec_session *sess, > > * @offset: offset in the VIFIFO where the associated packet was written > > * @flags: the vb2_v4l2_buffer flags > > */ > > -void amvdec_add_ts(struct amvdec_session *sess, u64 ts, > > - struct v4l2_timecode tc, u32 offset, u32 flags); > > +int amvdec_add_ts(struct amvdec_session *sess, u64 ts, > > + struct v4l2_timecode tc, u32 offset, u32 flags); > > void amvdec_remove_ts(struct amvdec_session *sess, u64 ts); > > > > /** > Let's inspect: I posted a probable solution the 09/12/2021 in a reply to 20211209085840.2081024-1-jiasheng@iscas.ac.cn : ===================><============================= diff --git a/drivers/staging/media/meson/vdec/esparser.c b/drivers/staging/media/meson/vdec/esparser.c index db7022707ff8..df733eff9ac7 100644 --- a/drivers/staging/media/meson/vdec/esparser.c +++ b/drivers/staging/media/meson/vdec/esparser.c @@ -328,7 +328,11 @@ esparser_queue(struct amvdec_session *sess, struct vb2_v4l2_buffer *vbuf) offset = esparser_get_offset(sess); - amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags); + ret = amvdec_add_ts(sess, vb->timestamp, vbuf->timecode, offset, vbuf->flags); + if (ret) { + v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR); + return ret; + } dev_dbg(core->dev, "esparser: ts = %llu pld_size = %u offset = %08X flags = %08X\n", vb->timestamp, payload_size, offset, vbuf->flags); diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c index b9125c295d1d..593b2ccbece2 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.c +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c @@ -227,13 +227,15 @@ int amvdec_set_canvases(struct amvdec_session *sess, } EXPORT_SYMBOL_GPL(amvdec_set_canvases); -void amvdec_add_ts(struct amvdec_session *sess, u64 ts, - struct v4l2_timecode tc, u32 offset, u32 vbuf_flags) +int amvdec_add_ts(struct amvdec_session *sess, u64 ts, + struct v4l2_timecode tc, u32 offset, u32 vbuf_flags) { struct amvdec_timestamp *new_ts; unsigned long flags; new_ts = kzalloc(sizeof(*new_ts), GFP_KERNEL); + if (!new_ts) + return -ENOMEM; new_ts->ts = ts; new_ts->tc = tc; new_ts->offset = offset; diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.h b/drivers/staging/media/meson/vdec/vdec_helpers.h index 88137d15aa3a..4bf3e61d081b 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.h +++ b/drivers/staging/media/meson/vdec/vdec_helpers.h @@ -56,8 +56,8 @@ void amvdec_dst_buf_done_offset(struct amvdec_session *sess, * @offset: offset in the VIFIFO where the associated packet was written * @flags: the vb2_v4l2_buffer flags */ -void amvdec_add_ts(struct amvdec_session *sess, u64 ts, - struct v4l2_timecode tc, u32 offset, u32 flags); +int amvdec_add_ts(struct amvdec_session *sess, u64 ts, + struct v4l2_timecode tc, u32 offset, u32 flags); void amvdec_remove_ts(struct amvdec_session *sess, u64 ts); ===================><============================= Then the patches were sent: - 20211210015620.2143555-1-jiasheng@iscas.ac.cn on 10/12/2021 - 20211215033535.40422-1-zhou1615@umn.edu on 15/12/2021 They are extremely close but not similar, mostly indenting differs. Both patches have the missing final "return 0" in amvdec_add_ts which is missing in my proposal. But only 20211210015620.2143555-1-jiasheng@iscas.ac.cn has the correct "if (ret)" in esparser_queue(). Patch 20211215033535.40422-1-zhou1615@umn.ed has a wrong "if (!ret)". But when comparing, 20211215033535.40422-1-zhou1615@umn.edu is an almost exact copy of my proposal, minus the fixes and the bogus return check. To be honest, there is a limited way to fix this, it's probable 20211215033535.40422-1-zhou1615@umn.edu was written independently from my proposal since there is a bug return check, and 20211210015620.2143555-1-jiasheng@iscas.ac.cn was rewritten from my proposal. Since 20211215033535.40422-1-zhou1615@umn.ed has a bogus return check, it should be naked. I'll only ask 20211210015620.2143555-1-jiasheng@iscas.ac.cn to be resent with a "Suggested-by" and indentation fixed like my proposal. Neil ^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-01-12 8:57 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-11-30 16:12 [PATCH] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() Zhou Qingyang 2021-12-01 8:41 ` Dan Carpenter 2021-12-02 16:03 ` [PATCH v2] " Zhou Qingyang 2021-12-03 13:30 ` Dan Carpenter 2021-12-14 13:46 ` Mauro Carvalho Chehab 2021-12-14 14:16 ` Greg Kroah-Hartman 2021-12-15 3:35 ` [PATCH v3] " Zhou Qingyang 2022-01-11 9:16 ` Hans Verkuil [not found] ` <CA+Cm_xSOv5NnW5GXcKKGi8bQSvT45iH6=65YJk3EG6uW0c5_Vw@mail.gmail.com> 2022-01-12 8:57 ` Neil Armstrong
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).