Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7354874imu; Tue, 22 Jan 2019 04:46:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN5bPq4Zh2eyq0Z2Z5EF8fwAXf892Dv/0M4qTsokfAurAuwtbYldcyo3kr4X60IW7BZ605qq X-Received: by 2002:a63:1c61:: with SMTP id c33mr30931243pgm.354.1548161213676; Tue, 22 Jan 2019 04:46:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548161213; cv=none; d=google.com; s=arc-20160816; b=LletOVHV2aC82MrLTI5+6lhSVFCHHyAkpP9QkpmU/Hz4YFdfYtprwHOqZJK4bdeyxT Aq791KXwywCfB/x5fNCns1OSei54GOMpJKsZTpkRmR9JmFQiB+QwgBU/rkpp39rCG85Y 0/dGK1dhItiBnmlA1NBy/U9MIw1Bv41VHfDZUhWy+F42ZXPwCQMcx9KyUYlvo1bbHUwx CtQJnEu3QNrJmIIexIziROcc6Ektu2leJQ+0+18nyD4mDIXhQ1bXXwLQEqlz+BgCj+kB J4l9cnwl56Biqicsm2SLzn51gTOw6XGSJnYZ1W8HpkuxegY29vYsRUeo1EAE2/OIg5vN yKMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=9Vza7aXrhgTBTR/MyZd58WK8K/Hb/j4DhtwDJID30AM=; b=JrCGD8qz2f1OXCNkzNWbq1zVrCvYG9hhFuDo0640pICeH4+tiq7cZu0ubSV1rFUZg6 87WyAV7Q5reYJAYFq8I7SQ6nr8APvLP/+t3PMd3cn6KPDZpmafDTc0WU3NwPy6qy9bRv m3OjsbtZRsUixRaw28C4BjU8OTHL+uoW4BmKT32BUjmxaMdDRkfxFNn/wUYo0coml3vf S6o8Lfqqq1A2/OcmW6inrY+iZNX8TlptFv4xTAMHQSE2kDXG5r/IwjGi2Dy+TF13JRtt FJXT5vpkF6o6DXqCipMdqK4/JDDij+KmzgYXx0hDLkIDcWhG6WJ7ofRCNagN6YmSaD5O sheg== ARC-Authentication-Results: i=1; mx.google.com; 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 c37si3334936pgm.156.2019.01.22.04.46.38; Tue, 22 Jan 2019 04:46:53 -0800 (PST) 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; 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 S1728440AbfAVMpb (ORCPT + 99 others); Tue, 22 Jan 2019 07:45:31 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:36558 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728233AbfAVMp2 (ORCPT ); Tue, 22 Jan 2019 07:45:28 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id AD7B9F58786A2DDCE85F; Tue, 22 Jan 2019 20:45:25 +0800 (CST) Received: from huawei.com (10.175.104.208) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.408.0; Tue, 22 Jan 2019 20:45:23 +0800 From: Liu Jian To: CC: , Subject: [PATCH v2 2/2] driver: uio: fix possible use-after-free in __uio_register_device Date: Wed, 23 Jan 2019 06:45:38 +0800 Message-ID: <1548197138-352285-3-git-send-email-liujian56@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548197138-352285-1-git-send-email-liujian56@huawei.com> References: <1548197138-352285-1-git-send-email-liujian56@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.104.208] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In uio_dev_add_attributes() error handing case, idev is used after device_unregister(), in which 'idev' has been released, touch idev cause use-after-free. Fixes: a93e7b331568 ("uio: Prevent device destruction while fds are open") Signed-off-by: Liu Jian Reviewed-by: Hamish Martin --- drivers/uio/uio.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 4d20220..7ee21c8 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -946,6 +946,7 @@ int __uio_register_device(struct module *owner, return ret; } + device_initialize(&idev->dev); idev->dev.devt = MKDEV(uio_major, idev->minor); idev->dev.class = &uio_class; idev->dev.parent = parent; @@ -956,7 +957,7 @@ int __uio_register_device(struct module *owner, if (ret) goto err_device_create; - ret = device_register(&idev->dev); + ret = device_add(&idev->dev); if (ret) goto err_device_create; @@ -988,9 +989,10 @@ int __uio_register_device(struct module *owner, err_request_irq: uio_dev_del_attributes(idev); err_uio_dev_add_attributes: - device_unregister(&idev->dev); + device_del(&idev->dev); err_device_create: uio_free_minor(idev); + put_device(&idev->dev); return ret; } EXPORT_SYMBOL_GPL(__uio_register_device); -- 2.7.4