Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752632AbdLGUia (ORCPT ); Thu, 7 Dec 2017 15:38:30 -0500 Received: from mail-sn1nam02on0087.outbound.protection.outlook.com ([104.47.36.87]:58678 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750929AbdLGUi2 (ORCPT ); Thu, 7 Dec 2017 15:38:28 -0500 From: "Madhani, Himanshu" To: Max Kellermann CC: "gregkh@linuxfoundation.org" , "linux-scsi@vger.kernel.org" , Dept-Eng QLA2xxx Upstream , "max.kellermann@gmail.com" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] drivers/scsi/qla2xxx: fix double free bug after firmware timeout Thread-Topic: [PATCH] drivers/scsi/qla2xxx: fix double free bug after firmware timeout Thread-Index: AQHTb2o5ppMeXm2FRUOlFE76ZxZnyKM4V9AA Date: Thu, 7 Dec 2017 20:38:23 +0000 Message-ID: References: <151265800413.23884.12590131670697249849.stgit@rabbit.intern.cm-ag> In-Reply-To: <151265800413.23884.12590131670697249849.stgit@rabbit.intern.cm-ag> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Himanshu.Madhani@cavium.com; x-originating-ip: [173.186.134.106] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MWHPR07MB3454;6:eKpn4Am0jRsgILCtSDoTOn8D0FtMMsWmyrsSlIEfSPVFzWiqXZYihCAmhWyazHYO6N0gpGs7Vs2m66FOI693c0xcrU6+cMrBClJpJl9FDivISGmJio7o3AXO1ExRa948c80XGXr003Kf04Jv2i5c5XphnFO32tH0XNcrbhzCNaBJE2pdFzKfpH4vHh5rEUVGnMeaiALYiPrjXKKT16R/+nPfUcqdJVZtMz+zZtAVoD0ah3EHgmrbOmn03tyrU1IA70AaThiRNSWc07tGfUa61Eawl1I9tsQB/4UwDvxZxmC7xIjOLF5Y+OfligOO2ikU2MBCKDpIrbYfrc4LsR3j2gtnFkKZO/MkrDbHAFzfkxI=;5:qsQ7AFSiL5UBUNU6W0nVOYdqWekRrnULSj75RfUhmNrjKM2tt4BOztD/Trd/oQ3W2D6VZ6pe6LdfjUdAAtRAauGJ/j1A1RysLQjFP9+S2JLULoxVUYdGx2yk/2AEjF47cCkd38bsNdqDSRB1ZQ5C8MDjfkBDxyYVmljQCTUZIc8=;24:nKwh8Mp9ouv56PT3E5VeZxwlCYDJHzZLs9snF7XG08rsgq5n+qYJCxATNH1J5zADmtL8lAisOaA8OM5GTLrQIan/VTAvvylzXsuKc4K8qvA=;7:OoH3ZbfQLLI5oMrcaDJCErzU+G3rwZpiRMrVAIW4LDzpum9c0NZQcCUqwnZPcNNm1FB3aKQToG0wK6QDG/bHnu/EeGNSpD3vbYp14KBN9dkvBBWDB4v1XOzzwWGnFWk/rEGsxSH9ipsMqDor+k8e0lJ2bhtaQ55U7Z8N/LMpMQgzb/18o04yRIz8ly1CyuU1dltSZpQIs6+dIJfk0uAGnPbX6AX04B0N9bOPMizyQFWjvm4jupQ5gEbg8LzThrZk x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 4c481a43-071b-4b79-220b-08d53db27615 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603304);SRVR:MWHPR07MB3454; x-ms-traffictypediagnostic: MWHPR07MB3454: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(8121501046)(5005006)(3231022)(3002001)(10201501046)(93006095)(93001095)(6041248)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(6072148)(201708071742011);SRVR:MWHPR07MB3454;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:MWHPR07MB3454; x-forefront-prvs: 05143A8241 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(346002)(366004)(24454002)(189003)(199004)(6506006)(3280700002)(36756003)(68736007)(6116002)(2900100001)(33656002)(101416001)(106356001)(76176011)(83716003)(66066001)(39060400002)(105586002)(53546010)(14454004)(102836003)(2906002)(8936002)(82746002)(5660300001)(3660700001)(316002)(99286004)(72206003)(97736004)(6486002)(305945005)(81156014)(54906003)(8676002)(6246003)(3846002)(77096006)(6916009)(53936002)(25786009)(6512007)(2950100002)(4326008)(81166006)(7736002)(86362001)(6436002)(229853002)(478600001);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR07MB3454;H:MWHPR07MB3455.namprd07.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: MIME-Version: 1.0 X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c481a43-071b-4b79-220b-08d53db27615 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Dec 2017 20:38:23.4862 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR07MB3454 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id vB7Kcb5i008900 Content-Length: 2658 Lines: 84 Hi Max, > On Dec 7, 2017, at 6:46 AM, Max Kellermann wrote: > > When the qla2xxx firmware is unavailable, eventually > qla2x00_sp_timeout() is reached, which calls the timeout function and > frees the srb_t instance. > > The timeout function always resolves to qla2x00_async_iocb_timeout(), > which invokes another callback function called "done". All of these > qla2x00_*_sp_done() callbacks also free the srb_t instance; after > returning to qla2x00_sp_timeout(), it is freed again. > > The fix is to remove the "sp->free(sp)" call from qla2x00_sp_timeout() > and add it to those code paths in qla2x00_async_iocb_timeout() which > do not already free the object. > > This is how it looks like with KASAN: > > BUG: KASAN: use-after-free in qla2x00_sp_timeout+0x228/0x250 > Read of size 8 at addr ffff88278147a590 by task swapper/2/0 > > Allocated by task 1502: > save_stack+0x33/0xa0 > kasan_kmalloc+0xa0/0xd0 > kmem_cache_alloc+0xb8/0x1c0 > mempool_alloc+0xd6/0x260 > qla24xx_async_gnl+0x3c5/0x1100 > > Freed by task 0: > save_stack+0x33/0xa0 > kasan_slab_free+0x72/0xc0 > kmem_cache_free+0x75/0x200 > qla24xx_async_gnl_sp_done+0x556/0x9e0 > qla2x00_async_iocb_timeout+0x1c7/0x420 > qla2x00_sp_timeout+0x16d/0x250 > call_timer_fn+0x36/0x200 > > The buggy address belongs to the object at ffff88278147a440 > which belongs to the cache qla2xxx_srbs of size 344 > The buggy address is located 336 bytes inside of > 344-byte region [ffff88278147a440, ffff88278147a598) > > Signed-off-by: Max Kellermann > --- > drivers/scsi/qla2xxx/qla_init.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c > index b5b48ddca962..801890564e00 100644 > --- a/drivers/scsi/qla2xxx/qla_init.c > +++ b/drivers/scsi/qla2xxx/qla_init.c > @@ -58,7 +58,6 @@ qla2x00_sp_timeout(unsigned long __data) > req->outstanding_cmds[sp->handle] = NULL; > iocb = &sp->u.iocb_cmd; > iocb->timeout(sp); > - sp->free(sp); > spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); > } > > @@ -121,9 +120,11 @@ qla2x00_async_iocb_timeout(void *data) > ea.data[1] = lio->u.logio.data[1]; > ea.sp = sp; > qla24xx_handle_plogi_done_event(fcport->vha, &ea); > + sp->free(sp); > break; > case SRB_LOGOUT_CMD: > qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT); > + sp->free(sp); > break; > case SRB_CT_PTHRU_CMD: > case SRB_MB_IOCB: > NACK These calls are asynchronous calls and free should be called by completion. I am going to send updates to driver which we have fixed similar issue for 4.16 Thanks, - Himanshu