From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 566D5C433EF for ; Tue, 11 Jan 2022 09:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:References:Cc:To:Subject: From:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0ulheOEPslIcW5l8vQauQG8tmizOmOIYGPyghIv8td4=; b=GVNfHrRo/08vEs iByeenQosy6IuooektVNaIVR2SjvY1xKHwsgAL5+xygWWt7DTEXMG0ncDoDBmtYh2zJlRK4rzD4EX z0x/8btbUs1RjXOLcIFJ5IM+mzFFCRWwLqc4vEvENnAOWKM1eP9vOSxBRxpvMmkxcURUr2VbT4WWx Tvj8SJK3isptkp19Kb/IEMAsTKjPzQa3SYa+zOrQHpwqwGWiO0iKPOiPn+sEORzguAqoJqyUJsDi/ xsoTc60Q2Sahd2wlI1zUTRhzUgt0JJLZnaij9h4YgZiCjButRtLBlNpnTy5WGR+83yW/d/1zGlYN/ sZdJQ6GK7V1L+gCJVEPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7DH1-00FW8E-5m; Tue, 11 Jan 2022 09:16:59 +0000 Received: from ewsoutbound.kpnmail.nl ([195.121.94.167]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7DGl-00FW1P-6h for linux-amlogic@lists.infradead.org; Tue, 11 Jan 2022 09:16:46 +0000 X-KPN-MessageId: 18605330-72bf-11ec-9a2e-005056abbe64 Received: from smtp.kpnmail.nl (unknown [10.31.155.40]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 18605330-72bf-11ec-9a2e-005056abbe64; Tue, 11 Jan 2022 10:16:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=xs4all01; h=content-type:to:subject:from:mime-version:date:message-id; bh=7sMnICIvN+Dgs1egxxA2KorGhnbnx8+H8ysgISZGjBM=; b=O+VWJ3fydQKr/WgCwUUWXqnzQFTBFgG0EkTTMJdLmewLsT7CZ9ZmNi0fzC2sjZH8qofQDk8eHZOIO nluQUA6GemGvglSxLCKhGbeDxd2ESFKRdmPi3okyQpmYBPi4K0uaAVCn8zxWCjOp0tk3puIezD7PUa anmqUQEQoXK9oRFTwq1DVA0NHAz5zbXWeVYHEd7u0ld6iqzwvx1tggBoprZ15A4nRiVReO1aLLUyV5 vzY39+LOROlWjCUvbkKPKMmEtkraXwY+iSaxL4MQ01zm1MFEit8WoqepKUz37CR3iAxv3QM4I+XnAv VV7GAtjvHB2HPpDVdhAujnXiTVfmYMg== X-KPN-VerifiedSender: No X-CMASSUN: 33|yDCXCyXpplCIeGif+s2ZnTO+p3G+Zr6ynyRziGuFOJP6KoBiLoJbafN8cEzivH+ cB1dtil5/MYuCW00gRos5CA== X-Originating-IP: 193.91.129.219 Received: from [192.168.2.10] (cdb815bc1.dhcp.as2116.net [193.91.129.219]) by smtp.xs4all.nl (Halon) with ESMTPSA id 2dbeb6da-72bf-11ec-b76f-005056ab7584; Tue, 11 Jan 2022 10:16:38 +0100 (CET) Message-ID: <368bc1b7-ff86-beaa-6749-afbe5960eaeb@xs4all.nl> Date: Tue, 11 Jan 2022 10:16:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.4.1 From: Hans Verkuil Subject: Re: [PATCH v3] media: meson: vdec: Fix a NULL pointer dereference in amvdec_add_ts() To: Zhou Qingyang , Neil Armstrong Cc: kjlu@umn.edu, Mauro Carvalho Chehab , Greg Kroah-Hartman , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Maxime Jourdan , linux-media@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20211214144613.35fec82a@coco.lan> <20211215033535.40422-1-zhou1615@umn.edu> Content-Language: en-US In-Reply-To: <20211215033535.40422-1-zhou1615@umn.edu> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220111_011643_998055_CA0BAEEF X-CRM114-Status: GOOD ( 27.60 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org 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 > --- > > [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); > > /** _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic