Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2958645imu; Sun, 27 Jan 2019 17:57:54 -0800 (PST) X-Google-Smtp-Source: ALg8bN6ZHip/mZ8CWJE4xRbIOq+APGVkiX3hCSFbCAJc1ON4zXs8pfafuvKt9+pyd6dfTf5mhfK3 X-Received: by 2002:a62:5fc4:: with SMTP id t187mr20343053pfb.66.1548640674898; Sun, 27 Jan 2019 17:57:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548640674; cv=none; d=google.com; s=arc-20160816; b=nG5SQe6ENUoSmJ9zth0PyQZ2vVyQN+w6uuXyH+4R3D5P2MUAMqRezM1TwX/G5DBii/ M7z0meC5Li8mkUTVIG9pJtl0Hlb+bHZkwquYct1BGUh+N1IvTwZt6NS2y/AqsXgT/uBj oYx9+HR8FqjkFekNzsCSPKtpn8OuHqKAR/5zIK/qOWYp8WaZKZoZyzqXJWoZ4LiCABGR A8Y0o2RLCjWcwOufVgbPKc6auXSygvuv+/W9nmxlvqDfRP7CFoPN5/ktALDy15LH3xWq gBWt1FzRweH8LCnU0/Qjtz0puB9WcxAdrowIYStsFWFPCSjSDGVTMb78aOSdsIDR57re fNQQ== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=vM0/D5QMgeTWNpcI78V9v2a+ne4tUHZBhFT6w/vpN4o=; b=midwhstZKWTwiCzrx4066lIKJPBrUGWRu4VzsnaH6AupwCuFq2LojC3SpxcUwIEvBc BRLW49vMxNep5fyvjVre4U2E18Nn8Je0JrUBEL3Z2gVijBq8qrli6WewwuqQHuRSob5v HT8SGUuVX7+u0xiyTnykD/Wi6gzs74DxQczazAmsV+RCQ9OwuAZLa1lEY0lGoL62ta1G DTtZbIybTUO6qLsh0flQpc4dINNiYtf0xZAYPr2BK6D/n/VjN+sLLXZ2B0ADUG277vRr EWZbwlAc9HsIeXMi1jJEFCd1MI5IhZ/Osb4ASKPiJS31nN6eqbvW+zACVSqfjI8N4uij jX+g== 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 v141si34704120pfc.260.2019.01.27.17.57.08; Sun, 27 Jan 2019 17:57:54 -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 S1726602AbfA1Bxl (ORCPT + 99 others); Sun, 27 Jan 2019 20:53:41 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:52894 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726511AbfA1Bxl (ORCPT ); Sun, 27 Jan 2019 20:53:41 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EC982CF592FDD882AF67; Mon, 28 Jan 2019 09:53:38 +0800 (CST) Received: from [127.0.0.1] (10.177.19.219) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.408.0; Mon, 28 Jan 2019 09:53:31 +0800 Subject: Re: [Openipmi-developer] [PATCH v2] ipmi_si: fix use-after-free of resource->name To: References: <1548494094-14356-1-git-send-email-yangyingliang@huawei.com> <20190126150809.GA11354@minyard.net> CC: , , , , , , From: Yang Yingliang Message-ID: <5C4E609A.7050609@huawei.com> Date: Mon, 28 Jan 2019 09:53:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <20190126150809.GA11354@minyard.net> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.19.219] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/1/26 23:08, Corey Minyard wrote: > On Sat, Jan 26, 2019 at 05:14:54PM +0800, Yang Yingliang wrote: >> When we excute the following commands, we got oops >> rmmod ipmi_si >> cat /proc/ioports >> > snip.. > >> If io_setup is called successful in try_smi_init() but try_smi_init() >> goes out_err before calling ipmi_register_smi(), so ipmi_unregister_smi() >> will not be called while removing module. It leads to the resource that >> allocated in io_setup() can not be freed, but the name(DEVICE_NAME) of >> resource is freed while removing the module. It causes use-after-free >> when cat /proc/ioports. >> >> Fix this by calling io_cleanup() while try_smi_init() goes to out_err >> and don't call release_region() if request_region() is not called to >> avoid error prints. >> >> Fixes: 93c303d2045b ("ipmi_si: Clean up shutdown a bit") >> Cc: stable@vger.kernel.org >> Reported-by: NuoHan Qiao >> Suggested-by: Corey Minyard >> Signed-off-by: Yang Yingliang >> --- >> drivers/char/ipmi/ipmi_si_intf.c | 5 +++++ >> drivers/char/ipmi/ipmi_si_port_io.c | 3 +++ >> 2 files changed, 8 insertions(+) >> >> diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c >> index dc8603d..f1b9fda 100644 >> --- a/drivers/char/ipmi/ipmi_si_intf.c >> +++ b/drivers/char/ipmi/ipmi_si_intf.c >> @@ -2085,6 +2085,11 @@ static int try_smi_init(struct smi_info *new_smi) >> WARN_ON(new_smi->io.dev->init_name != NULL); >> >> out_err: >> + if (rv && new_smi->io.io_cleanup) { >> + new_smi->io.io_cleanup(&new_smi->io); >> + new_smi->io.io_cleanup = NULL; >> + } >> + >> kfree(init_name); >> return rv; >> } >> diff --git a/drivers/char/ipmi/ipmi_si_port_io.c b/drivers/char/ipmi/ipmi_si_port_io.c >> index ef6dffc..0c46a3f 100644 >> --- a/drivers/char/ipmi/ipmi_si_port_io.c >> +++ b/drivers/char/ipmi/ipmi_si_port_io.c >> @@ -53,6 +53,9 @@ static void port_cleanup(struct si_sm_io *io) >> unsigned int addr = io->addr_data; >> int idx; >> >> + if (io->regsize != 1 && io->regsize != 2 && io->regsize != 4) >> + return; >> + > Why do you need this part? I can't see the reason for it. The addr > part below should handle that, especially with the above change. > > -corey If ipmi_si_port_setup() returns in default case, request_region() won't be called, so we don't need to call release_region() or it will prints some warning messages like this "Trying to free nonexistent resource...". We don't need call io_cleanup() until the io_setup() returns successful. How about change this part like this: diff --git a/drivers/char/ipmi/ipmi_si_port_io.c b/drivers/char/ipmi/ipmi_si_port_io.c index ef6dffc..03924c3 100644 --- a/drivers/char/ipmi/ipmi_si_port_io.c +++ b/drivers/char/ipmi/ipmi_si_port_io.c @@ -68,8 +68,6 @@ int ipmi_si_port_setup(struct si_sm_io *io) if (!addr) return -ENODEV; - io->io_cleanup = port_cleanup; - /* * Figure out the actual inb/inw/inl/etc routine to use based * upon the register size. @@ -109,5 +107,8 @@ int ipmi_si_port_setup(struct si_sm_io *io) return -EIO; } } + + io->io_cleanup = port_cleanup; + return 0; } Thanks, Yang > >> if (addr) { >> for (idx = 0; idx < io->io_size; idx++) >> release_region(addr + idx * io->regspacing, >> -- >> 1.8.3 >> >> >> >> >> _______________________________________________ >> Openipmi-developer mailing list >> Openipmi-developer@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/openipmi-developer > . >