From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF720158D8B for ; Wed, 18 Dec 2024 07:19:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.11.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734506397; cv=none; b=TvAW5IhIORclJJTUseASzpgSGrauyXdlytbbOHCmGY+grw5FBXj175r0h5mw3BQw6yAs0XVDketzkz8m8qvqsS9bgcY1MHHbljhaEnlECchaXLghNBqFlhuo13joUa8VSyKuLizBDjxH2TSwAEmHJMid7mIL4c8R07Q1AtkMg4Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734506397; c=relaxed/simple; bh=kvpFytqC84m6Dz2jAVxRv12O8mTE5p29X4ah5oS1qRM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kz49HQq4s9Vb4K7DmbxGuP9BP64gcjmxKLGI891Pm50qlRROLjXF12EqL7tyXxeqzbJ09WqIso5XHuhzYtdU9wTEIIKSuUaUczQV6pkc5kHGv8opYddxt4QfCndOjeQUDTQOA9SohwhN2ROAgbfU7vCJiI+A2rxppfFWkUkShGo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=pass smtp.mailfrom=lst.de; arc=none smtp.client-ip=213.95.11.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lst.de Received: by verein.lst.de (Postfix, from userid 2407) id 574D968AA6; Wed, 18 Dec 2024 08:19:50 +0100 (CET) Date: Wed, 18 Dec 2024 08:19:49 +0100 From: Christoph Hellwig To: Leo Stone Cc: syzbot+ff4aab278fa7e27e0f9e@syzkaller.appspotmail.com, hch@lst.de, sagi@grimberg.me, kch@nvidia.com, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-nvme@lists.infradead.org Subject: Re: [PATCH] nvmet: Don't overflow subsysnqn Message-ID: <20241218071949.GA25990@lst.de> References: <6761b929.050a0220.29fcd0.0070.GAE@google.com> <20241218005909.89092-2-leocstone@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241218005909.89092-2-leocstone@gmail.com> User-Agent: Mutt/1.5.17 (2007-11-01) On Tue, Dec 17, 2024 at 04:59:10PM -0800, Leo Stone wrote: > nvmet_root_discovery_nqn_store treats the subsysnqn string like a fixed > size buffer, even though it is dynamically allocated to the size of the > string. > > Create a new string with kstrdup instead of using the old buffer. > > Reported-by: syzbot+ff4aab278fa7e27e0f9e@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=ff4aab278fa7e27e0f9e > Fixes: 95409e277d83 ("nvmet: implement unique discovery NQN") > Signed-off-by: Leo Stone > --- > drivers/nvme/target/configfs.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c > index eeee9e9b854c..3fa25f9f7d92 100644 > --- a/drivers/nvme/target/configfs.c > +++ b/drivers/nvme/target/configfs.c > @@ -2271,8 +2271,8 @@ static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item, > return -EINVAL; > } > } > - memset(nvmet_disc_subsys->subsysnqn, 0, NVMF_NQN_FIELD_LEN); > - memcpy(nvmet_disc_subsys->subsysnqn, page, len); > + kfree(nvmet_disc_subsys->subsysnqn); > + nvmet_disc_subsys->subsysnqn = kstrdup(page, GFP_KERNEL); This needs error handling, pobably best done by using a local variable for the new allocation, which would also help to keep it outside the lock.