Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4245372imu; Mon, 7 Jan 2019 19:02:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN6bkzGUgKxx6I1DmHWpm+MGyTY5YIKIBrXct0+SJjkAEpPR+DwvwOBudrJg0OLCOb4JN/eg X-Received: by 2002:a63:580a:: with SMTP id m10mr36607pgb.332.1546916570496; Mon, 07 Jan 2019 19:02:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546916570; cv=none; d=google.com; s=arc-20160816; b=QdIZyeSf+5Q4rwr9wZcOQGUNVtGFGuSbPj6xMJ2M3+WlKkqsM+1HzF1H12ZtpxirLz f+PKMbVjBl8o2E/jsp63yr/kMdjQc58AeaIGIjm5cRpPn6rwxkK6yai+9rgFX1TxonxV 9BI14q+PLq7OlZMf8cx1Wo8pj972EDIjbSTp3COe6G1fJPigFJrZv+2yJgWQ/aue/cEG 8ZPE1weBD9jFj9IbbWcmSsnxJ8xeGn0l+wOtLkbu6YrHqhLqqo8mkWqjoQaI/n6tkXi5 oMY1br0bgsJu+YslYE+hbxW7Wa0VxCWSwFGDDJBuoQhdu279bLCjjVdqRSiRje4kdHI+ hA7A== 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=1PWyuRPvJKonAUweTcpo0xyShAqUF0KnN9HIf0tybPg=; b=d+h49oMjQZcfCnP1Ke8oml7MWNDvQ/+kMSXz0cEhTdyYWE95yKdMurAei8hzu53Ufo 4XvATXSbDWRxGLsWinLuq4dc4/1zxYn52a7gzw8PLSQAjzPiuPgmFqFNSRRVkRmfKZTL 95PeihAUpqcIYTMEwO6/jk6W8/T8CIiaJnDsfDEbHyt2xUxDgD7Og1b4vcFUafjsEhnS i1Xq3qLnZOpN8hoVR2XHH6A+4c1dO8fAdTrwI3GSUpa2fOoRRchmB+09wDIAZ66pqMAE UBj9ZK1BVJD+28ql+iSTXuJDLWaGia/FDqSn+2MwPbPpSMPLZWlg7ezHENYgbSbHKCut oMkA== 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 h3si43304446pll.116.2019.01.07.19.02.33; Mon, 07 Jan 2019 19:02:50 -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 S1727494AbfAHDBL (ORCPT + 99 others); Mon, 7 Jan 2019 22:01:11 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:17121 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727052AbfAHDBK (ORCPT ); Mon, 7 Jan 2019 22:01:10 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 34A37CF87FCD97B93580; Tue, 8 Jan 2019 11:01:08 +0800 (CST) Received: from huawei.com (10.175.104.208) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.408.0; Tue, 8 Jan 2019 11:01:02 +0800 From: Liu Jian To: , CC: , Subject: [PATCH 2/2] driver: uio: fix possible use-after-free in __uio_register_device Date: Tue, 8 Jan 2019 21:01:48 +0800 Message-ID: <1546952508-186003-3-git-send-email-liujian56@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546952508-186003-1-git-send-email-liujian56@huawei.com> References: <1546952508-186003-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 From: liujian 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 7280552..be2a943 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -945,6 +945,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; @@ -955,7 +956,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; @@ -987,9 +988,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