Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1989582ybv; Fri, 21 Feb 2020 06:55:48 -0800 (PST) X-Google-Smtp-Source: APXvYqxKXeyblN0lZNemIYtSVKMqPhEcWqEg0V7tac/heXbxgOQUZh496Vgr7KttndSD55OfiS+n X-Received: by 2002:aca:ab51:: with SMTP id u78mr2265714oie.21.1582296948790; Fri, 21 Feb 2020 06:55:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582296948; cv=none; d=google.com; s=arc-20160816; b=NZC28myCKEAtPdT8uIrnrUcJdj70xb1GHEXwKdiws29Cujqk7hoLHEBOreeBmbGgKI f7UsXwv0fkeuLEHzqdLllJ7zlBYlaHEollTLfe+zzzaXwoYob4dxC5keA7pTDeFcplxV vFyxZyAGLb5kkqV3oMeCCvELJ0HGu5x/bpR4JsrsBrcTbtT2YXamAwhmc4sX91q6MRs8 MgFBjBnWocqZNT6m70qSVjh4myhkyXEMfShi9Eru0B6b4cnGo8FvjzzA6IKK7+xcMCeD 565+EZ9GlzTYFFz3r6v7ydn4CVVSnRpY+YlntGoKV1nIVwa4dyq6yhFNCgKqtQUqzkym eOaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=/FYKk/LpyWkSGsa50E891mYDlXK+nD1zgSCT0i41OUM=; b=PaEHgthXFrFXmMygCKKiATdi89m4KZ1h2azsWrZo6bHtwaOVhQMaoNXQCpUKYU6nh6 woqUk1yrJxmUBksqLNiZbuqNFWV1aKg7oEmYX1InEYkBP0YS4/zE6nParRJX8jZ9JB2r x+tRtrbBP0sd/RWur/BBMjCdozzq9/miQ6my6yG2upQHjhMpO9/g13r5ST3WXH+A7cfw q2TlBRL1bz4VifUAd89b6CzvOCpqcFJs/AmFhW06gCjeYztDJ4oQFgZLVGijH56ex1JQ nUmPXv5dDQYF0YxfBD5XR2YrmrlLBJJqNP+BFCkZ30YVxJZRe+QvkLq976fTV0nRAqOU A4cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S0ZPFoKE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z20si791029oib.26.2020.02.21.06.55.35; Fri, 21 Feb 2020 06:55:48 -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; dkim=pass header.i=@kernel.org header.s=default header.b=S0ZPFoKE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728873AbgBUOyi (ORCPT + 99 others); Fri, 21 Feb 2020 09:54:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:60372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728436AbgBUOyh (ORCPT ); Fri, 21 Feb 2020 09:54:37 -0500 Received: from redsun51.ssa.fujisawa.hgst.com (unknown [199.255.47.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4FE35206DB; Fri, 21 Feb 2020 14:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582296877; bh=G4uoI6dvX3xr+aBRpwhQPxpuOp02TZ5SCzvj3XzCwZ8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S0ZPFoKEsKBEwzyW1yri/0CS2t8tN6h7EZSAQy7RFM2kbaMeF7S/IT83/3OHSXvmk d1w51tCR6xvOb4bYU1nfJFvIItt65sXdriyQKwptPV4Ut5RAzmSFU840PPTX7e9xD/ E6IdwtgBspNF2e5awD6kI6hUGJTrDGTvEhItwjhk= Date: Fri, 21 Feb 2020 23:54:32 +0900 From: Keith Busch To: Logan Gunthorpe Cc: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, Jens Axboe , Christoph Hellwig , Sagi Grimberg Subject: Re: [PATCH] nvme-multipath: Fix memory leak with ana_log_buf Message-ID: <20200221145432.GA15144@redsun51.ssa.fujisawa.hgst.com> References: <20200220202953.26139-1-logang@deltatee.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200220202953.26139-1-logang@deltatee.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 20, 2020 at 01:29:53PM -0700, Logan Gunthorpe wrote: > kmemleak reports a memory leak with the ana_log_buf allocated by > nvme_mpath_init(): > > unreferenced object 0xffff888120e94000 (size 8208): > comm "nvme", pid 6884, jiffies 4295020435 (age 78786.312s) > hex dump (first 32 bytes): > 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 ................ > 01 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ................ > backtrace: > [<00000000e2360188>] kmalloc_order+0x97/0xc0 > [<0000000079b18dd4>] kmalloc_order_trace+0x24/0x100 > [<00000000f50c0406>] __kmalloc+0x24c/0x2d0 > [<00000000f31a10b9>] nvme_mpath_init+0x23c/0x2b0 > [<000000005802589e>] nvme_init_identify+0x75f/0x1600 > [<0000000058ef911b>] nvme_loop_configure_admin_queue+0x26d/0x280 > [<00000000673774b9>] nvme_loop_create_ctrl+0x2a7/0x710 > [<00000000f1c7a233>] nvmf_dev_write+0xc66/0x10b9 > [<000000004199f8d0>] __vfs_write+0x50/0xa0 > [<0000000065466fef>] vfs_write+0xf3/0x280 > [<00000000b0db9a8b>] ksys_write+0xc6/0x160 > [<0000000082156b91>] __x64_sys_write+0x43/0x50 > [<00000000c34fbb6d>] do_syscall_64+0x77/0x2f0 > [<00000000bbc574c9>] entry_SYSCALL_64_after_hwframe+0x49/0xbe > > nvme_mpath_init() is called by nvme_init_identify() which is called in > multiple places (nvme_reset_work(), nvme_passthru_end(), etc). This > means nvme_mpath_init() may be called multiple times before > nvme_mpath_uninit() (which is only called on nvme_free_ctrl()). > > When nvme_mpath_init() is called multiple times, it overwrites the > ana_log_buf pointer with a new allocation, thus leaking the previous > allocation. > > To fix this, free ana_log_buf before allocating a new one. > > Signed-off-by: Logan Gunthorpe Thanks, applied to 5.6-rc3 with the reviews and the fixes tag.