Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1077392pxb; Thu, 19 Nov 2020 23:57:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYNlngAFJV02t9Tj74/y3X4LTazQhgtInNflWNK1wCGf4HK1oq41d1VnX50DU4DdcYNRMa X-Received: by 2002:a17:906:a996:: with SMTP id jr22mr32477883ejb.463.1605859078115; Thu, 19 Nov 2020 23:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605859078; cv=none; d=google.com; s=arc-20160816; b=xNVY4mQj/OkMlQymxRV2hLFOcJW9MJ/EK86iOTCSvF4tWHBe8v0SlgMQmF9DnrMID6 CSok7hYdXz+GYoWt14fSKF4Zk3DKqGr18PDbOQeZhIUKyuzwnwsYmG0FmuShpsanD9Q2 OXk75rSZKVk/O7Gr/ln9MV1i4WG9AVUHEtAkCemxEWJEox5jYsP5InKHscvRalmhiDMP gz4IojzCeqbOgZnOZ9oyPuTXPTUTcs2ernv6pHcqN0zoi0vCFQxxFBI0aeLx2TVzDhZS jysPqfC+eqhiJA8VA5bd9iQbnXbWtVfFzlmcqbjCnrHR5Nxu3Z2+HGTXMWJXYK2MaPeP Kiaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=ZmsWa73xJX7Zl/5qDm9Mu9Q7eTlqakfw9KEp58NMOX4=; b=Na81eECE6VlPKXT7s5VZqDPXIx8R7Ny64X30XhLzDYkaSlu3qdoNVgL6ehEYqvqvlr X78YW4dndPUaP7T2azDsZQ7Rl7yb6RXcVHPvc4v2Z4O81quojKFmDi6d2AGKe9tZzlwV fyaJkbE6KG2MhsCCQOeaho1ytepYsNMs6f4XJV71Y0Xt5wxSLmavMduBQ3qX6Ge4Pyl3 rrQiti0XzxvemrDYlef5QRjlpcNouZMGZ5oxtzN78TS2ddL74Pl6tTlgBUGeMKLVSk5A g4JQ+rDouMPlEi/ms7eElykwBuF5Oobkvn260832cC2DFPSmnASVbugeEF9puDBOZIHi Gj1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bz7zgQlw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bh4si1492504ejb.551.2020.11.19.23.57.33; Thu, 19 Nov 2020 23:57:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bz7zgQlw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726540AbgKTHzi (ORCPT + 99 others); Fri, 20 Nov 2020 02:55:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20813 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbgKTHzi (ORCPT ); Fri, 20 Nov 2020 02:55:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605858937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZmsWa73xJX7Zl/5qDm9Mu9Q7eTlqakfw9KEp58NMOX4=; b=bz7zgQlwTSHwRLuGCaulmBy+JYzf3p6d7nqV0aSXLzRttLPW/YnciQH+2FVWaAY1MgIl2R 6r+tx6skG/CV1S2bQN/7uj9QaeeN3c/48KodTfDCXTlXnjV5VmqsVI0jtgBp8KhTObyfmI ItQGTgFbuNpIAID6VMgD3MK2p2UZyTU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-556-QQqtNERFNX-rsBb1AvrZOg-1; Fri, 20 Nov 2020 02:55:33 -0500 X-MC-Unique: QQqtNERFNX-rsBb1AvrZOg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 992BC107ACE3; Fri, 20 Nov 2020 07:55:31 +0000 (UTC) Received: from gondolin (ovpn-112-250.ams2.redhat.com [10.36.112.250]) by smtp.corp.redhat.com (Postfix) with ESMTP id E40A619D9B; Fri, 20 Nov 2020 07:55:29 +0000 (UTC) Date: Fri, 20 Nov 2020 08:55:26 +0100 From: Cornelia Huck To: Qinglang Miao Cc: Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , , Subject: Re: [PATCH] s390: cio: fix two use-after-free bugs in device.c Message-ID: <20201120085526.257a5596.cohuck@redhat.com> In-Reply-To: <20201120074849.31557-1-miaoqinglang@huawei.com> References: <20201120074849.31557-1-miaoqinglang@huawei.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Nov 2020 15:48:49 +0800 Qinglang Miao wrote: > put_device calls release function which do kfree() inside. > So following use of sch&cdev would cause use-after-free bugs. > > Fix these by simply adjusting the position of put_device. > > Fixes: 37db8985b211 ("s390/cio: add basic protected virtualization support") > Fixes: 74bd0d859dc3 ("s390/cio: fix unlocked access of online member") > Reported-by: Hulk Robot > Signed-off-by: Qinglang Miao > --- > drivers/s390/cio/device.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c > index b29fe8d50..69492417b 100644 > --- a/drivers/s390/cio/device.c > +++ b/drivers/s390/cio/device.c > @@ -1664,10 +1664,10 @@ void __init ccw_device_destroy_console(struct ccw_device *cdev) > struct io_subchannel_private *io_priv = to_io_private(sch); > > set_io_private(sch, NULL); > - put_device(&sch->dev); > - put_device(&cdev->dev); > dma_free_coherent(&sch->dev, sizeof(*io_priv->dma_area), > io_priv->dma_area, io_priv->dma_area_dma); > + put_device(&sch->dev); > + put_device(&cdev->dev); That change looks reasonable. > kfree(io_priv); > } > > @@ -1774,8 +1774,8 @@ static int ccw_device_remove(struct device *dev) > ret, cdev->private->dev_id.ssid, > cdev->private->dev_id.devno); > /* Give up reference obtained in ccw_device_set_online(). */ > - put_device(&cdev->dev); > spin_lock_irq(cdev->ccwlock); > + put_device(&cdev->dev); As the comment above states, the put_device() gives up the reference obtained in ccw_device_set_online(). There's at least one more reference remaining (held by the caller of the remove function). Moving the put_device() does not fix anything here. > } > ccw_device_set_timeout(cdev, 0); > cdev->drv = NULL;