Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754652AbeAIQjf (ORCPT + 1 other); Tue, 9 Jan 2018 11:39:35 -0500 Received: from mga11.intel.com ([192.55.52.93]:31450 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752128AbeAIQjd (ORCPT ); Tue, 9 Jan 2018 11:39:33 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,336,1511856000"; d="scan'208";a="20216797" Date: Tue, 9 Jan 2018 09:42:52 -0700 From: Keith Busch To: Johannes Thumshirn Cc: Christoph Hellwig , Sagi Grimberg , Linux Kernel Mailinglist , Linux NVMe Mailinglist , Alexander Potapenko Subject: Re: [PATCH] nvme: initialize hostid uuid in nvmf_host_default to not leak kernel memory Message-ID: <20180109164252.GD15154@localhost.localdomain> References: <20180109152043.30422-1-jthumshirn@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180109152043.30422-1-jthumshirn@suse.de> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Tue, Jan 09, 2018 at 04:20:43PM +0100, Johannes Thumshirn wrote: > Alexander reports: > according to KMSAN (and common sense as well) the following code in > drivers/nvme/host/fabrics.c > (http://elixir.free-electrons.com/linux/latest/source/drivers/nvme/host/fabrics.c#L68): > > 72 host = kmalloc(sizeof(*host), GFP_KERNEL); > 73 if (!host) > 74 return NULL; > 75 > 76 kref_init(&host->ref); > 77 snprintf(host->nqn, NVMF_NQN_SIZE, > 78 "nqn.2014-08.org.nvmexpress:uuid:%pUb", &host->id); > > uses uninitialized heap memory to generate the unique id for the NVMF host. > If I'm understanding correctly, it can be then passed to the > userspace, so the contents of the uninitialized chunk may potentially > leak. > If the specification doesn't rely on this UID to be random or unique, > I suggest using kzalloc() here, otherwise it might be a good idea to > use a real RNG. > > this assumption is correct so initialize the host->id using uuid_gen() as > it was done before commit 6bfe04255d5e ("nvme: add hostid token to fabric > options"). > > Fixes: 6bfe04255d5e ("nvme: add hostid token to fabric options") > Reported-by: Alexander Potapenko > Signed-off-by: Johannes Thumshirn Thanks for the report and the fix. It'd still be good to use the kzalloc variant in addition to this. Reviewed-by: Keith Busch