Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp769720lqh; Thu, 28 Mar 2024 16:25:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9+I0BNQn8sQ1yqNLfeWYncuNKLwaMjTUN9L3sRd/78jn2s9E0RjFl3pnFtUCCIA2p8xKRLUk0RPNNQ4vRyd1r3pkTbKuPAOZPznx6XQ== X-Google-Smtp-Source: AGHT+IETAYgM0wERP7D0cfBdBBQyXO5GludHsEc6OO65MUmViIRxAEoYNfKWfotbY+T3WIiYUQUB X-Received: by 2002:a17:906:e02:b0:a4a:3679:5514 with SMTP id l2-20020a1709060e0200b00a4a36795514mr449889eji.48.1711668312248; Thu, 28 Mar 2024 16:25:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711668312; cv=pass; d=google.com; s=arc-20160816; b=dN7ntqAgj+zhPg0vmmjXQ3xRXQ14PWIvaqNlQcz7N1HisegPk5FdmzIkcew96SWpNZ 04+oT405k1N1w+dzi3UiC9At+U5yY2VdFSVXJFF7GP8z0rqizqwdvjDhW7SjzhpWPqbz CylK176ADtufM6bLx0nIjTbwpXY9qP7RDAH1G63O5n9zn+b8vfK1ZSwj5AdqbyTyJgEi tcvrwQseWGDaDmS1vjuZ2LnzU0/YRM2pBrX/QOYlrQvnlPOpxgUQ2hlp7XV6rVK115fU OjFySVxsiPafrVifIIzTUFenZC+yeCEPEHKq84fHdxgs2cBw+OCCm5nrGEmwaB529ZuX mZ6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=/qNXZWa7ff+gZO9/7qJdAv1MXiheIN0/3fR3ZzkSZyM=; fh=Tf3ngz3geNGO31CuB4DR+sW53LF/AVKDpnxnm1wf8ig=; b=nF7MM9r89lJ/1q/sjBG25MuJLbwMYCECXvNk0/l7HPFPPqm7Fn03EGAsV2oMDzUnXd R6cpdjB8Qp0T7hRGIajhvtzwzrOweSOBTibNPCX+QystDQ9wMd0qJ/6RXwgMDxle+SFG NDPpn9djoQyoz2CxzrQMsEo9RP3L8a9Apefs/sOBf4IcsUPrc2UirhBcv5NAzwyt8HnV zVoH4dCQOfluXEPi5yZGW2R3c12v4Mu+xluURfncR0T6ojacq8m4Ez+0sKZRpPRghgxG ZfMJVm2+N9i11HYDbJaw+4WwTcA+81O49osd4MzTtILYl9uHW+tnKVddEFcSb0DFIFBw dqxg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Fslp7Mww; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-123825-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123825-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p21-20020a170906229500b00a4df0612177si1144178eja.343.2024.03.28.16.25.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:25:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123825-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Fslp7Mww; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-123825-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123825-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CC4381F22534 for ; Thu, 28 Mar 2024 23:25:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8BBF213342A; Thu, 28 Mar 2024 23:25:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Fslp7Mww" Received: from mail-io1-f48.google.com (mail-io1-f48.google.com [209.85.166.48]) (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 36A9382882 for ; Thu, 28 Mar 2024 23:25:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711668301; cv=none; b=TR1MWAxvH0lJxDX1utuUqwUfSBVnhMS1qXb6xqUyv68zTkUHp9LbNN2lvH+kqPohp3OQX1pQEssfvIjMcI7EjeAZrEiyV4xEpahOWjHDhHaxwTPvniGL15qItBykvgq7fwA8aLpTXNNN17UxJkp4d6cpozqlPLM3N6LBqLlqELk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711668301; c=relaxed/simple; bh=wXfg/+AxvkOnFrYF3BJt/cT/EGxwBVaS6XpJy/hWFFA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f4KuPZNzIiFAKv+q/KIQrV7ZM4d/KwwQmIEF9y1ZMRbRX8rrtPvYCe9KA8PZIfeSmhllZvSYNr0XjLgfKGaOcCcXrO1+Lf76kKcneYa8R4nO28BdgTxbRT674e/Pf6iAihAKKwT1IjZK6JBMFc4ZdsFwyGUKZee2lIz7xv9edrg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Fslp7Mww; arc=none smtp.client-ip=209.85.166.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-io1-f48.google.com with SMTP id ca18e2360f4ac-7d08aea7546so51071239f.0 for ; Thu, 28 Mar 2024 16:25:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711668299; x=1712273099; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=/qNXZWa7ff+gZO9/7qJdAv1MXiheIN0/3fR3ZzkSZyM=; b=Fslp7MwwrIxxIMJnOJTvA6zxB4REFHZxdCr3XoHBqqm7DH2VVCTOZWES3LC0T0NdMd UDjlyzUQcHrOmWC6v+KCIs7+JGgDRLoHSRSsLzDwWQ+XqjdfA/Ct5eY3TVJrycSiC9rw ZhcBF8Z8gXiE417zpi17qtvaVBdneGcQ3BfaLx31Ar8S/TqqrZVRKh4ikgDdgr1COqum ugD6FBHoRLtLN/vUoRdJhSsqBgp5SaGFqis1I4shN25SVMH8XLZ3DHdZKMJlxRSYzLeM YA08FETKMRCik3wPo83TqidqOu1L+I8+Ffc9WeX+lL9UM73+NLYvR0sgbKvTrPAplFnk 7IgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711668299; x=1712273099; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/qNXZWa7ff+gZO9/7qJdAv1MXiheIN0/3fR3ZzkSZyM=; b=BM9DGyhJHMqeeXj2fy2uBZuSjXfIaCSa7knrcictFImVzeMqgMUw5rY8SpNzcU3oAD ++Hypym7angFsc9F8wWok7+OoJv8epd/iQT/ubn369zezcxxjH05V0majWHzXrQZWzbo wniaBrUjdpJznpFTv7Wmcj5FqeZA5+FG4trlTdbBuQZ+xLGwHhZlrYhqJHLaDgmwL4Y+ /79TqyY+1yCKvOdcWONqcGTQG1s9v+iTfkBwzl6SMnKYFDcGMgWxyRnkvdlyJsE8nzSa 0wDzOV736fwsgo4R3Vz3hojCCfmzK5V1jks7hEwTLdB4TGYDxV1yt3OhHfqNi9NxWUrk u7DA== X-Gm-Message-State: AOJu0YxU2S6Dc0Tuvg42aG9I6N44FVR3IK+4WdDWQLgCk9E/usVb8fN8 f4kID/M7Kk+cMGZIpc9XEcmEh0SwJd9j32R+9TvVvViuPHuqrNAuCpNqJssvdQ== X-Received: by 2002:a5d:8454:0:b0:7d0:807d:33dc with SMTP id w20-20020a5d8454000000b007d0807d33dcmr699533ior.15.1711668299282; Thu, 28 Mar 2024 16:24:59 -0700 (PDT) Received: from google.com (30.64.135.34.bc.googleusercontent.com. [34.135.64.30]) by smtp.gmail.com with ESMTPSA id x15-20020a6bda0f000000b007d06ef8020bsm669877iob.40.2024.03.28.16.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:24:58 -0700 (PDT) Date: Thu, 28 Mar 2024 23:24:56 +0000 From: Justin Stitt To: Arnd Bergmann Cc: linux-kernel@vger.kernel.org, "Richard Russon (FlatCap)" , Jens Axboe , Arnd Bergmann , linux-ntfs-dev@lists.sourceforge.net, linux-block@vger.kernel.org Subject: Re: [PATCH 07/11] block/partitions/ldm: convert strncpy() to strscpy() Message-ID: References: <20240328140512.4148825-1-arnd@kernel.org> <20240328140512.4148825-8-arnd@kernel.org> 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: <20240328140512.4148825-8-arnd@kernel.org> Hi, On Thu, Mar 28, 2024 at 03:04:51PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > The strncpy() here can cause a non-terminated string, which older gcc > versions such as gcc-9 warn about: > > In function 'ldm_parse_tocblock', > inlined from 'ldm_validate_tocblocks' at block/partitions/ldm.c:386:7, > inlined from 'ldm_partition' at block/partitions/ldm.c:1457:7: > block/partitions/ldm.c:134:2: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation] > 134 | strncpy (toc->bitmap1_name, data + 0x24, sizeof (toc->bitmap1_name)); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > block/partitions/ldm.c:145:2: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation] > 145 | strncpy (toc->bitmap2_name, data + 0x46, sizeof (toc->bitmap2_name)); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > New versions notice that the code is correct after all because of the > following termination, but replacing the strncpy() with strscpy_pad() > or strcpy() avoids the warning and simplifies the code at the same time. > > Use the padding version here to keep the existing behavior, in case > the code relies on not including uninitialized data. > > Signed-off-by: Arnd Bergmann Thanks for the patch! This helps towards: https://github.com/KSPP/linux/issues/90 Reviewed-by: Justin Stitt > --- > block/partitions/ldm.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c > index 38e58960ae03..2bd42fedb907 100644 > --- a/block/partitions/ldm.c > +++ b/block/partitions/ldm.c > @@ -131,8 +131,7 @@ static bool ldm_parse_tocblock (const u8 *data, struct tocblock *toc) > ldm_crit ("Cannot find TOCBLOCK, database may be corrupt."); > return false; > } > - strncpy (toc->bitmap1_name, data + 0x24, sizeof (toc->bitmap1_name)); > - toc->bitmap1_name[sizeof (toc->bitmap1_name) - 1] = 0; > + strscpy_pad(toc->bitmap1_name, data + 0x24, sizeof(toc->bitmap1_name)); > toc->bitmap1_start = get_unaligned_be64(data + 0x2E); > toc->bitmap1_size = get_unaligned_be64(data + 0x36); > > @@ -142,8 +141,7 @@ static bool ldm_parse_tocblock (const u8 *data, struct tocblock *toc) > TOC_BITMAP1, toc->bitmap1_name); > return false; > } > - strncpy (toc->bitmap2_name, data + 0x46, sizeof (toc->bitmap2_name)); > - toc->bitmap2_name[sizeof (toc->bitmap2_name) - 1] = 0; > + strscpy_pad(toc->bitmap2_name, data + 0x46, sizeof(toc->bitmap2_name)); > toc->bitmap2_start = get_unaligned_be64(data + 0x50); > toc->bitmap2_size = get_unaligned_be64(data + 0x58); > if (strncmp (toc->bitmap2_name, TOC_BITMAP2, > -- > 2.39.2 > Thanks Justin