From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796123214; b=v9yFJrRqlE29eqVUR1qL4RH+1ZCQXWGsc4ko7fEWCBHcKPEX67w62Vt3BrhtW6jRD3xK d1g4cGxzHP/jE7aAU9uK7yb4P6HHyS7z+6xa9Vsxjewg2YTINRJYGw2x3FcwlNz518cAp kGPvc2urcwIpCSPRXyJGWyGgDqPVcTBSKHYc+d9EbPyHNpszrul5l4O9WQhvveekw67N3 qIUC/nFWMaA014v+dAMHx+KgyOKZ15OzuqQhqvdXcG+mr2SS3JQydeYGkr6odiZRxSe6C wNQWc3vK4NvVq3s5yV83nlDhA9I2G5gbLZ5328lm8lskYbiNd/7eJuEQwsrE1toHGyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796123214; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:Organization: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=3Vg2/I2S/xC28IlIkViNF7rv2bif2vuZwb0hgxdpkWY=; b=pbUszOEjF4w7Ut62ABo3Ek5kNbFiz0LZ2j4JWQ/9GAViVodyPYMlM+8ckhK3k5wJB1MZ WIqxoER1SuxedmNQ1YWtWOXdqjl1ukyBaup9AGIUPaDKORDXfGNGFJ1PhN4NtR5MV8Wa0 DbUuI2AcFvDyalEq3n3WVezthV9bnJW8lpiVLVr3sFOQ8GTDzOiqKI9cl9i8aMBxpybN/ nQwxDK0LbSFB1KEgM+dKllBnUaQD3qHqZ1eHcxVMX3EqCfNOAlLCfF536CliEGCn2L6Tg NPol9vUIi8yPhPnXKhqQZLlwemxAbyOTQtNHIkEqVRUr6AvGdih4LOA24vsKbJfF1XA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J1RgDWmZ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E16A7606A31A; Tue, 1 Dec 2026 11:06:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J1RgDWmZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DB741F00893; Tue, 1 Dec 2026 11:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796123213; bh=3Vg2/I2S/xC28IlIkViNF7rv2bif2vuZwb0hgxdpkWY=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=J1RgDWmZmGZrbKSN6PBMPOZ0o+Bi+cpHL4/vYeLn381yj/HLsBpCrQkEXrT3I3/sd F8ipJX4qipzImpjugVA0K8veiEOC6pJ9zIVh5uqMciv3zYMOslHR3ZOLezM03B5Gle chPwNR6hlih69s+yqFu4yPZ/9N2/fDpJ0A18yexVi486aCV4+jTVuErzeeOSBdvNco W5KcE9X92BVKRbXjLsqjNe6neWHA5jFrANDSvgxqQ4fanSGVYu2PcUi0q5XFgKdmke W3YlL7YCkMbpaUJSndvRDtp7eFeqw0/cB0sjzEFiDvhlu3J2p4ukdAkjR/GIxxR4Si 1Lo/rrQPGJIIQ== Message-ID: <3f39a119-bbb2-40ed-8107-a20f8ea87fd9@kernel.org> Date: Tue, 1 Dec 2026 20:06:50 +0900 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/3] dm zoned: handle labels that are not NUL-terminated To: Yingjie Wang , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski Cc: "dm-devel@lists.linux.dev" , "linux-kernel@vger.kernel.org" , Hannes Reinecke , "stable@vger.kernel.org" References: <20261201105558.117053-1-x-professor@outlook.com> <20261201105625.117301-1-x-professor@outlook.com> Content-Language: en-US From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20261201105625.117301-1-x-professor@outlook.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/1/26 19:56, Yingjie Wang wrote: > If the label in the superblock uses all 32 bytes, it is not > NUL-terminated. It is copied to zmd->label, which has the same size and > is used as a string. With CONFIG_FORTIFY_SOURCE, the next call of > dmz_check_sb() crashes: > > strlen: detected buffer overflow: 33 byte read of buffer size 32 > kernel BUG at lib/string_helpers.c:1044! > > If the label does not match, it is also printed directly from the > superblock, which can read past the end of the block: > > BUG: KASAN: use-after-free in string > Read of size 1 > > Add space for the terminating NUL byte to zmd->label, and limit the > length of the label that is printed. dmzadm does not create such > labels. > > Fixes: bd5c40313a14 ("dm zoned: metadata version 2") > Cc: stable@vger.kernel.org > Signed-off-by: Yingjie Wang > --- > drivers/md/dm-zoned-metadata.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c > index 64e0edaa0044..04ae8e2b3627 100644 > --- a/drivers/md/dm-zoned-metadata.c > +++ b/drivers/md/dm-zoned-metadata.c > @@ -145,7 +145,7 @@ struct dmz_metadata { > unsigned int nr_devs; > > char devname[BDEVNAME_SIZE]; > - char label[BDEVNAME_SIZE]; > + char label[BDEVNAME_SIZE + 1]; This alone does not guarantee that the label is NUL terminated either. Who says that this was written with dmzadm or that a chnage in dmzadm introduces a bug? So the strlen() call below can still crash. So in addition to this change, we should check that the label has a terminating NUL character and reject the device as broken otherwise. > uuid_t uuid; > > sector_t zone_bitmap_size; > @@ -1026,7 +1026,7 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb, > } > if (strlen(zmd->label) && > memcmp(zmd->label, sb->dmz_label, BDEVNAME_SIZE)) { > - dmz_dev_err(dev, "mismatching DM-Zoned label, is %s expected %s", > + dmz_dev_err(dev, "mismatching DM-Zoned label, is %.32s expected %s", With the above suggested additional check, this change will not be needed. > sb->dmz_label, zmd->label); > return -ENXIO; > } -- Damien Le Moal Western Digital Research