From patchwork Wed Nov 6 02:36:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: <> X-Patchwork-Id: 11229139 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6E4A1515 for ; Wed, 6 Nov 2019 02:36:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA6CF2087E for ; Wed, 6 Nov 2019 02:36:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730988AbfKFCgm (ORCPT ); Tue, 5 Nov 2019 21:36:42 -0500 Received: from cnc.isely.net ([75.149.91.89]:40189 "EHLO cnc.isely.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730585AbfKFCgm (ORCPT ); Tue, 5 Nov 2019 21:36:42 -0500 Received: from ts3-dock2.isely.net (ts3-dock2.isely.net [::ffff:192.168.23.14]) (AUTH: PLAIN isely, TLS: TLSv1/SSLv3,256bits,DHE-RSA-AES256-GCM-SHA384) by cnc.isely.net with ESMTPSA; Tue, 05 Nov 2019 20:36:40 -0600 id 00000000001426E0.000000005DC231B8.00000351 Date: Tue, 5 Nov 2019 20:36:40 -0600 (CST) X-X-Sender: isely@sheridan.isely.net Reply-To: Mike Isely at pobox From: <> To: Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, Linux Kernel Mailing List cc: Mike Isely at pobox Subject: [PATCH] pvrusb2: Fix oops on tear-down when radio support is not present Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) Mime-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In some device configurations there's no radio or radio support in the driver. That's OK, as the driver sets itself up accordingly. However on tear-down in these caes it's still trying to tear down radio related context when there isn't anything there, leading to dereferences through a null pointer and chaos follows. How this bug survived unfixed for 11 years in the pvrusb2 driver is a mystery to me. Signed-off-by: Mike Isely --- drivers/media/usb/pvrusb2/pvrusb2-v4l2.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c index aa4fbc3e88cc..339119f6cc23 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c @@ -909,8 +909,12 @@ static void pvr2_v4l2_internal_check(struct pvr2_channel *chp) pvr2_v4l2_dev_disassociate_parent(vp->dev_video); pvr2_v4l2_dev_disassociate_parent(vp->dev_radio); if (!list_empty(&vp->dev_video->devbase.fh_list) || - !list_empty(&vp->dev_radio->devbase.fh_list)) + ((vp->dev_radio != NULL) && + !list_empty(&vp->dev_radio->devbase.fh_list))) { + pvr2_trace(PVR2_TRACE_STRUCT, + "pvr2_v4l2 internal_check exit-empty id=%p", vp); return; + } pvr2_v4l2_destroy_no_lock(vp); } @@ -946,7 +950,8 @@ static int pvr2_v4l2_release(struct file *file) kfree(fhp); if (vp->channel.mc_head->disconnect_flag && list_empty(&vp->dev_video->devbase.fh_list) && - list_empty(&vp->dev_radio->devbase.fh_list)) { + ((vp->dev_radio == NULL) || + list_empty(&vp->dev_radio->devbase.fh_list))) { pvr2_v4l2_destroy_no_lock(vp); } return 0;