Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3822017ybi; Mon, 29 Jul 2019 13:17:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhfm5lE9K2F+5dbVO7jv7QRpAVfzPm1O9KqltEvem/Hzt9QWtUP1lQhUCmODUH4TVN1rND X-Received: by 2002:a17:902:145:: with SMTP id 63mr115161366plb.55.1564431466548; Mon, 29 Jul 2019 13:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564431466; cv=none; d=google.com; s=arc-20160816; b=hzzk4GWb4qWgCWPL/nWIhEQ84jYKSeW2h99hQ3Ethe/44A0h8F/586+mAyqJU7/+7z RhY/88g3tY8ySNF5NonjGw7QJYPiJdDKFIM6oDAxXmxnddvsiVDMv25j2+YmDCd7+Ixq SghYj+sUDGrc3/Zpv+kxvfMpI+KmRNYp8lig2kWzFfa5uedh6bJ0AqWcoWRqeTQLbU9T H8OSN2prEzSU5Ai4upVe8uX0Q3n8icu9KBsd5zbPeVOgzHon1Zf3T5EofQoLapYvji9E QZxdrNiAcPsl2Ask36cJx2z5E/Ktd7ZrG3zvcEURrrZwnz4UaKzv/IdWL1GirA0Rn5ya 7Elg== 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=lGwW1E6v6WGDXQCMYmIMoyYA4/ijFgkINf6XaIaa0ug=; b=OECVzBwMD1nW3XRp4UnKDSfcBF5ywL1D0+GEty3M8FWxCGX+0h4r3dyIedZCIFivCv 4+I09VOf67lqyE0eH1c060FlyaR7IU1L5PqmkGKOaZUlUvCI9LwHCBApdMmssG+F3YTV E/J/9kAwaJpIiJVVbAtYQg9NLkl7LQjceIPTIJRcIN0xn1ivvKzl444AFM3Wjyl3TkKj dib33gBu3RLoVvFcr7a+bwbuBQWnafmj1swOnFbMWGawUfHkp9K+sk1c3e8s4CtRdO3U KyBETuedcgeGBFAK9qvhqylSCBn713uwB9NMRdtsnKt/rP/IvpWEzYD5z7g5JzAlX+1g ZTUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pXRw0+2C; 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 124si4045060pga.499.2019.07.29.13.17.31; Mon, 29 Jul 2019 13:17:46 -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=pXRw0+2C; 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 S1729583AbfG2TZB (ORCPT + 99 others); Mon, 29 Jul 2019 15:25:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:37258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729562AbfG2TY7 (ORCPT ); Mon, 29 Jul 2019 15:24:59 -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 2EFE421655; Mon, 29 Jul 2019 19:24:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428297; bh=31Y3PFm7Rdq/mDBbzc0NKinDNh7RGDZq7CL7tzmrL0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pXRw0+2CjzZFzDvNCiGXEr9iM21AKUoVw6JFuoqpl7TRq+I5q3DvxAxDxgvr+S/4L fvdrRCncr5upTHyS/IW5sh2/2Ln6U0ddYNCchKFFBLJvXeveNu8IHqtcC3DsmCi1D8 1k+b0FZDC0aGK8gDuLvsifqy/q7mNc7K8iFFagCw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans Verkuil , Hulk Robot , Kefeng Wang , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.14 032/293] media: wl128x: Fix some error handling in fm_v4l2_init_video_device() Date: Mon, 29 Jul 2019 21:18:43 +0200 Message-Id: <20190729190824.373855223@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit 69fbb3f47327d959830c94bf31893972b8c8f700 ] X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected The fm_v4l2_init_video_device() forget to unregister v4l2/video device in the error path, it could lead to UAF issue, eg, BUG: KASAN: use-after-free in atomic64_read include/asm-generic/atomic-instrumented.h:836 [inline] BUG: KASAN: use-after-free in atomic_long_read include/asm-generic/atomic-long.h:28 [inline] BUG: KASAN: use-after-free in __mutex_unlock_slowpath+0x92/0x690 kernel/locking/mutex.c:1206 Read of size 8 at addr ffff8881e84a7c70 by task v4l_id/3659 CPU: 1 PID: 3659 Comm: v4l_id Not tainted 5.1.0 #8 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xa9/0x10e lib/dump_stack.c:113 print_address_description+0x65/0x270 mm/kasan/report.c:187 kasan_report+0x149/0x18d mm/kasan/report.c:317 atomic64_read include/asm-generic/atomic-instrumented.h:836 [inline] atomic_long_read include/asm-generic/atomic-long.h:28 [inline] __mutex_unlock_slowpath+0x92/0x690 kernel/locking/mutex.c:1206 fm_v4l2_fops_open+0xac/0x120 [fm_drv] v4l2_open+0x191/0x390 [videodev] chrdev_open+0x20d/0x570 fs/char_dev.c:417 do_dentry_open+0x700/0xf30 fs/open.c:777 do_last fs/namei.c:3416 [inline] path_openat+0x7c4/0x2a90 fs/namei.c:3532 do_filp_open+0x1a5/0x2b0 fs/namei.c:3563 do_sys_open+0x302/0x490 fs/open.c:1069 do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x7f8180c17c8e ... Allocated by task 3642: set_track mm/kasan/common.c:87 [inline] __kasan_kmalloc.constprop.3+0xa0/0xd0 mm/kasan/common.c:497 fm_drv_init+0x13/0x1000 [fm_drv] do_one_initcall+0xbc/0x47d init/main.c:901 do_init_module+0x1b5/0x547 kernel/module.c:3456 load_module+0x6405/0x8c10 kernel/module.c:3804 __do_sys_finit_module+0x162/0x190 kernel/module.c:3898 do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe Freed by task 3642: set_track mm/kasan/common.c:87 [inline] __kasan_slab_free+0x130/0x180 mm/kasan/common.c:459 slab_free_hook mm/slub.c:1429 [inline] slab_free_freelist_hook mm/slub.c:1456 [inline] slab_free mm/slub.c:3003 [inline] kfree+0xe1/0x270 mm/slub.c:3958 fm_drv_init+0x1e6/0x1000 [fm_drv] do_one_initcall+0xbc/0x47d init/main.c:901 do_init_module+0x1b5/0x547 kernel/module.c:3456 load_module+0x6405/0x8c10 kernel/module.c:3804 __do_sys_finit_module+0x162/0x190 kernel/module.c:3898 do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290 entry_SYSCALL_64_after_hwframe+0x49/0xbe Add relevant unregister functions to fix it. Cc: Hans Verkuil Reported-by: Hulk Robot Signed-off-by: Kefeng Wang Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/radio/wl128x/fmdrv_v4l2.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/media/radio/wl128x/fmdrv_v4l2.c b/drivers/media/radio/wl128x/fmdrv_v4l2.c index fc5a7abc83d2..77778c86e04d 100644 --- a/drivers/media/radio/wl128x/fmdrv_v4l2.c +++ b/drivers/media/radio/wl128x/fmdrv_v4l2.c @@ -549,6 +549,7 @@ int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr) /* Register with V4L2 subsystem as RADIO device */ if (video_register_device(&gradio_dev, VFL_TYPE_RADIO, radio_nr)) { + v4l2_device_unregister(&fmdev->v4l2_dev); fmerr("Could not register video device\n"); return -ENOMEM; } @@ -562,6 +563,8 @@ int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr) if (ret < 0) { fmerr("(fmdev): Can't init ctrl handler\n"); v4l2_ctrl_handler_free(&fmdev->ctrl_handler); + video_unregister_device(fmdev->radio_dev); + v4l2_device_unregister(&fmdev->v4l2_dev); return -EBUSY; } -- 2.20.1