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 X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01050C43381 for ; Fri, 22 Mar 2019 13:16:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C36372183E for ; Fri, 22 Mar 2019 13:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553260587; bh=aumAjMVBbcN1iTAZBxqRgDOay8HHYtyOjOsGO9txkM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=tkxrwQMmpKjuHi0M/i+C+qke4V14Am2N9eRFBTeyIEMxdZO+ic3kmc5QwQgOcWo1N gRlo+5lqDwLmIF60rBuGHB485DjVh3d00H5AXQEstBpRCYBNzEv36LOFkqbbBiay6o U81LelAsdf7n7oqpk4axJufrlaoqix7vOrZUgX8k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729171AbfCVL06 (ORCPT ); Fri, 22 Mar 2019 07:26:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:54692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729156AbfCVL05 (ORCPT ); Fri, 22 Mar 2019 07:26:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2DC7221B24; Fri, 22 Mar 2019 11:26:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553254016; bh=aumAjMVBbcN1iTAZBxqRgDOay8HHYtyOjOsGO9txkM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gLidCS2ygFAqVA2AlA9hpoux7sknbZjrKlCHTsIHXn41mZ0pvMs48/HF8qCrKFBvw 9pCuGU7I4/dKZazUjVio4xoQivzVme8r0IYi6bY+7IlrPzYIsaTavj1spqCzIx2lcr tfyPbFtvjw8Opq5h+xV1D/QBzFg9nRF+lPxAvVtM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chiranjeevi Rapolu , Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab Subject: [PATCH 3.18 133/134] media: uvcvideo: Avoid NULL pointer dereference at the end of streaming Date: Fri, 22 Mar 2019 12:15:46 +0100 Message-Id: <20190322111220.190717235@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111210.465931067@linuxfoundation.org> References: <20190322111210.465931067@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sakari Ailus commit 9dd0627d8d62a7ddb001a75f63942d92b5336561 upstream. The UVC video driver converts the timestamp from hardware specific unit to one known by the kernel at the time when the buffer is dequeued. This is fine in general, but the streamoff operation consists of the following steps (among other things): 1. uvc_video_clock_cleanup --- the hardware clock sample array is released and the pointer to the array is set to NULL, 2. buffers in active state are returned to the user and 3. buf_finish callback is called on buffers that are prepared. buf_finish includes calling uvc_video_clock_update that accesses the hardware clock sample array. The above is serialised by a queue specific mutex. Address the problem by skipping the clock conversion if the hardware clock sample array is already released. Fixes: 9c0863b1cc48 ("[media] vb2: call buf_finish from __queue_cancel") Reported-by: Chiranjeevi Rapolu Tested-by: Chiranjeevi Rapolu Signed-off-by: Sakari Ailus Cc: stable@vger.kernel.org Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/uvc/uvc_video.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -627,6 +627,14 @@ void uvc_video_clock_update(struct uvc_s u32 rem; u64 y; + /* + * We will get called from __vb2_queue_cancel() if there are buffers + * done but not dequeued by the user, but the sample array has already + * been released at that time. Just bail out in that case. + */ + if (!clock->samples) + return; + spin_lock_irqsave(&clock->lock, flags); if (clock->count < clock->size)