From nobody Thu Dec 18 07:53:36 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E301A2572 for ; Wed, 18 Dec 2024 00:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734483589; cv=none; b=YMCzJh8I6UcJPYERKBfLHhFRLyhJXmpcLPdLSrnA8WfGam4leL7JV0lKuUJwST91AJ3IPoqG6BQdsuoNdU+gttvaTXuNDeINq+7BHnoESTOTUpeZF70eqLGQS7JkBA+8qZOETvWf9XLvamygm6UD81AWpKBG1eDWltwed92/Sjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734483589; c=relaxed/simple; bh=u0QLNRxf5vPnBzeZJbe9Zi/XxpopAqtfEOUbO1pzFfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iCzapC3a+clWX8ZptCWpsYkaEsCztnwOU6asAoK3Zu3RGd91FsGnJaXkqdh5mzJMOuiJWnxuOF+Fi7kFzVgzrdGn+xc3SMmzY7zKnL5NYFF1P2ClG0VPcdeObi8Nv+IBeZcVl8e/lFNUxvT1JcJizwyeXccx/tHCOtiXlat9R4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RRoOklA3; arc=none smtp.client-ip=209.85.216.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RRoOklA3" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2ee6dd1dd5eso4578911a91.3 for ; Tue, 17 Dec 2024 16:59:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734483587; x=1735088387; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wyNzNC0qUpinVJr0mql6moq+skFI0tUgODaQVETnoRU=; b=RRoOklA3iwymANgKFzgb3UA+b7IiZWNIRj/VjoQoX/q/B9eDUdS789/Zr1Zqo5/6LH Em2FF4O3lda+Pbb3UdUGVE9m5xK/efk8iZ2QPK9y3btzjlQOOYYbYSKSU60vLuQSF68p VMMGxT/9xFjsGRKCnaLC6KFMEaIeUksWFpDPKB9Lh8s4yBuWwzCdKNrRlnP0dw0nVXCG n2Qp8unrGbC4nDSurguBLVXf6NKrA1m7OcFYc9HTQuF+JVJR6VDbsZmZZTIvB7NZ/Bom A5EgBJ7A833WRIZNGBe0tLKfJ6e2mVzY8YUaW9yimsu94m0mZN5jCWmPSC8284eSHptj lgcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734483587; x=1735088387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wyNzNC0qUpinVJr0mql6moq+skFI0tUgODaQVETnoRU=; b=fWyvuq6/YbsH5tibuMi9ZJRTZ5kxDtLwhcsC8hmXY5/RAAnf5vMyJFZGjvqVnU1dbx r0CG5GQZW/yu2d2u/yH/UZ77IRu3Qy1KaDa+lxiCb7stj25VfhbLTeC6TbEomvXZTeKb TVEdtLzAIFWjkF+nkIk1WHRMihGJPZtqBivTyxt+Ocfp84fRRrdV53/I5d8OjumWSj7L asxxzm9XMia0FY7e8AFfROm5RNAtUb55PJJRotm0wxW470+mAnfJhiB54RicQcebu+BI hDAtPp//VaBa3a2mRgummqVRXK5C6z/gIZ0U/ZQXhnn3V6k8QEKlBuvg1CtE9ywoX62p XiMQ== X-Gm-Message-State: AOJu0YwH1R8y2F04+KAoi/TZgMMVQpEDmFz2O4+zU0a8+6jRoydJFvaQ 5wbQ7STpfUrwwv/hE3SWiq2oT4yzS5naqSKHDX4wux9ACiNCCSSI X-Gm-Gg: ASbGnctw1kszFOeokR41g2Xm13mkGAaZXQjpmsz3i1Ti2WilPvNNxsy97yzP5HoCPDs Gv6zKEx8byUylglVUB1IGfzQ3+n+jsTaWReBza+9BCt2FZ6LIqg69R6A3tM6HcMAtqZojlc4U1H +DE08JF9SVB/gUSECP9eZzH1a4PGf25RdfbdmTwnpb0No/o35TiZq1meNrPdaKeRr/se8orGXa5 ksaGKx4+Ukvl7lxCaEDueYxuX9s4ayhipwOma7c8FvpuHo8z5+336lUaovnwvKS0Wf955qN X-Google-Smtp-Source: AGHT+IHyYIvDEU2mwF/4vZXZg+ysyyHMbcN+4K8Evw1EnFtDzMPyw2jnOAXYXvBbc50HbFE7aGtpJA== X-Received: by 2002:a17:90b:1c04:b0:2ee:fc08:1bc1 with SMTP id 98e67ed59e1d1-2f2e93a6effmr1433692a91.37.1734483587169; Tue, 17 Dec 2024 16:59:47 -0800 (PST) Received: from tc.hsd1.or.comcast.net ([2601:1c2:c104:170:8dfd:a38e:f80c:ebd2]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f2eda2dbe2sm152514a91.42.2024.12.17.16.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Dec 2024 16:59:46 -0800 (PST) From: Leo Stone To: syzbot+ff4aab278fa7e27e0f9e@syzkaller.appspotmail.com, hch@lst.de, sagi@grimberg.me, kch@nvidia.com Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-nvme@lists.infradead.org, Leo Stone Subject: [PATCH] nvmet: Don't overflow subsysnqn Date: Tue, 17 Dec 2024 16:59:10 -0800 Message-ID: <20241218005909.89092-2-leocstone@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <6761b929.050a0220.29fcd0.0070.GAE@google.com> References: <6761b929.050a0220.29fcd0.0070.GAE@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3Dff4aab278fa7e27e0f9e 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 =3D kstrdup(page, GFP_KERNEL); up_write(&nvmet_config_sem); =20 return len; --=20 2.43.0