Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp593487img; Fri, 22 Mar 2019 04:46:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVE6kRQlCBPgcyAqqLEgmc9jU8OSst3ldE0i6rlv/LbD1CVMkOEYOUKhQ4QWzfh8gg9w12 X-Received: by 2002:aa7:82cb:: with SMTP id f11mr1070637pfn.0.1553255180036; Fri, 22 Mar 2019 04:46:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553255180; cv=none; d=google.com; s=arc-20160816; b=q6AFpS9ly2ielQna6SWgkGolxU0XY2ymim4IGhjA/zUiN31Lv+GuyYQ6eh3BZmTRZ7 NARoFvo8cUp7MlUog0UTvY/u1nTnT2uQPtoZE/QbwI7pN8rJLwS91wxVk2AQaBZyAWOV Ji/qTukJcrluvWroUtGS/vnwC2WbzNHCLizd7q86ygggmXjnMQzDzLiWIhQDvNLtYLXp RXe4gy/VCsVYFYgyBd3qnkRTJQts0hyUzBHoTaQJPpL+/9vqo1tgYYolNbMRzXrzDDgd NJ05+v9zoBQu87SkMDCGw65U9keTCzFDZo76mjzLud233xR6pp3fKQwBTwI7GLfWbWXt UX+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CyiaB6zmzIAhRKU/++dSuou5uLzFIFJCIJYijRfVBc8=; b=KCd6IgUXdmONX0ErMNm0VRNlOb8OZLdkBG9ljwu69MXu6oxctIpfAqrbs8mTdcOd6/ cFep0/UG+QTDeGet+1bi723UeqQAu+iqDa9OfqkRWrnivlD0/2G615Fj3o/XCaFgsQoK /jay7IB2GL6ghBKJPwegtjsVxldUkdyfjr2naCdmdXZ/XgxrdXdzj1swfkC5gzz2KC8r tt/xX0F9dwYRzV2DeYQa7Pfpa3c1P8uQ2NLpo5Ap0GvfhkIflsssS37RV7TBX0KfoGZk 7HwUKceSGo8w3F7esvbiwDGJ7mjEPgTCcU0VIhZkH2UtmomUjgH5Zamis/3Y28V/l6p3 CWxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ML7eAMdX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h10si6264505pgs.573.2019.03.22.04.46.04; Fri, 22 Mar 2019 04:46:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ML7eAMdX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731948AbfCVLp1 (ORCPT + 99 others); Fri, 22 Mar 2019 07:45:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:48546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730976AbfCVLp0 (ORCPT ); Fri, 22 Mar 2019 07:45:26 -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 291152075E; Fri, 22 Mar 2019 11:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553255125; bh=FiRY7MkXhIt+1DHihyqBvcsNpH1RlQY7r6ijlSisWgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ML7eAMdXDb609yYkPDMyhrMpE1hML+oQiXFbjYMd424GLbIDGgHDnLAIqzFpYNOnG pbWxEA4M2FjmvX7KZvWCRQF6DGeq3ofeEF8IwSax8YiM/F4+KpV/rxbls/bLSiIC+m V1ee8Bz+8XIjccY/nJJG5RCq1Q5NoOGjf5eh5v+U= 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 4.9 114/118] media: uvcvideo: Avoid NULL pointer dereference at the end of streaming Date: Fri, 22 Mar 2019 12:16:26 +0100 Message-Id: <20190322111224.343744148@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111215.873964544@linuxfoundation.org> References: <20190322111215.873964544@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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-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 @@ -638,6 +638,14 @@ void uvc_video_clock_update(struct uvc_s if (!uvc_hw_timestamps_param) return; + /* + * 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)