Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp3051203lqz; Wed, 3 Apr 2024 17:24:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUT+VZZwUlSfAwqQ0AqPJrSy0Cvt4ObmsKV3SnOyztUTnO0MIan2PQ1Q9INjy/jUlvd0PMR+3+DSC7IPGpo9dGqc3dbEOMKPv6P4h2gYA== X-Google-Smtp-Source: AGHT+IE4YdzjcEo4znK8JQGIbS9NPScZJM4mfT3ATs1iGNvVC1OEUT42iktzc8sfg/SOBrQDDe9Q X-Received: by 2002:ac5:c8a3:0:b0:4d3:3f2b:dc63 with SMTP id o3-20020ac5c8a3000000b004d33f2bdc63mr832483vkl.5.1712190289473; Wed, 03 Apr 2024 17:24:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712190289; cv=pass; d=google.com; s=arc-20160816; b=F1bzS7lfl76CAR8MAH43sNRNW4ZSn7iiLxHqFbPuYjx58TPzx9WsxrWNhg6dNu/1zY 2Zu1Jagq5UmXSQs9mNRR6Tdq1sAoxpywbbxrOnJmbzgS4Y2NsXJvgRfdpGaXE7SKhSe2 3PiFkHrLO7XRQzikHh5ra2iQKk+WksPRmD31oChkyVPYjrBdDJeNRNnzTizUPIi0E+k/ e5XOSRPRJlUf5dBGiXAXF3faBwgu64jFLNkEIR9OrBUI8MCREEk7hjuUL6dpl+V4/oXt 5RzOB6SmjGsDYCNGjVSTcvxD/URGD2okljhN/wRdqhctPnSbhvtJy0z8/kZMjN+dKubi +WSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=vzWz7IdJMj61AY2xXdjLGAh4Sy+JwYaABh1sOf/dM44=; fh=/w7p5y5fmrx/ggu7eMJAB+pf6HLFJ1ZMEP2bS09te8I=; b=mEI0zBDsI6A0n4JL3500VgPesoKsqC42pRIVYBB9kxlk8C8fyWHqcYQ4CN0ruJrKjR JzO0gEvI4hwpoKvDYP5GMgcJASmB0ycaW3tpAdykrWB6nawZjb6wKDiCkBg04UH6syOa NAIKgzdW7bOus2ZXLzwA/W5Kece2KsjWdGXoABTXsgWFI/cIg6kZT/QoozB4AOJMTxVJ aKTL+rbNIDLIyEdAD2cV7pi6aSiOvRfjhYhTAQZcTxh772nv4qUFurrWAEjzBqGqoNrl A21p53K3lzR9X+Voxgq3kHDU9ZKiWOY8RLvYrUmJouI5m4TwjC/yFyNAOTia2jowZKis 1gNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KMaPozWs; 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-130780-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130780-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bt9-20020ad455c9000000b006969b6138dfsi14995477qvb.452.2024.04.03.17.24.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 17:24:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130780-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KMaPozWs; 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-130780-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130780-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 367831C275EE for ; Thu, 4 Apr 2024 00:24:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B5DE1865; Thu, 4 Apr 2024 00:24:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KMaPozWs" Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 95FF4ED9 for ; Thu, 4 Apr 2024 00:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712190282; cv=none; b=TZCgCKCMa0H7p0biX+pJvVZGQy2dlhMSVD4fTH1sTZ1UwtNI8azUcXzM5qiPDs8ITl3Pj1ujo+t8K4ruiQ6AK0loCizUfkPY8KXxMx/0HaQ02BH6xjBng8btOKqGKIT/bMxQ9zq+K+03F7BSrz+Q/vDYrUyJ/Cn9gR9SQbhD35o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712190282; c=relaxed/simple; bh=3JPZfsSQGYLv4i4aZfgMUDZ5L89pgYI3CBEmLS7s63U=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=rXenh5XBSqg2l2QsXBtnuNQhjBXYjcCHevxd1jXlS7bwP4pmiBLW/n7enagkOW/76g4jqwH5AVxpkhdyoscQFWALNcjaju74jYGkw5dawsZIsasNUjQAoQX2aeDZvqoD7QZ9Uf3lWCRJ7rKbMQB3bho/fml7nyS51abwuSnjsKY= 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=KMaPozWs; arc=none smtp.client-ip=209.85.218.45 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-ej1-f45.google.com with SMTP id a640c23a62f3a-a465ddc2c09so26135466b.2 for ; Wed, 03 Apr 2024 17:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712190279; x=1712795079; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vzWz7IdJMj61AY2xXdjLGAh4Sy+JwYaABh1sOf/dM44=; b=KMaPozWsVN5P9vWH6ET4TjKwL50yqmPH+Ji9xlZHQm3+VEx/X/u3KY8Nf1ayZHvDb2 VKJ3fZy2jzBVvn0i3XB5YzXkDJeLwbH6EMzCYMkTaO7Xn1yany02QbwH9i9hYZtgr+gQ Sg41kNyYisI1cNDwqrNpTpXE4ryRlFPA9lfkDKhZoEZL15UKq4Z97weJfl67Lqg+zID0 j231PvUszmcsJksZAyyuVjVNSnPVS56PXhh/KCfPaIYpI9KZAS5HWvmrYgqkRip4facw LRcoVEJaxP4TPN7YTtUA59J+sm+K+HV0Ci3dWdh+3PCO/Rr9S9wQtaL2qvWEUrzmN7Ps Jjmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712190279; x=1712795079; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vzWz7IdJMj61AY2xXdjLGAh4Sy+JwYaABh1sOf/dM44=; b=NBzo3setLu8iD7eXzlZvA6cBd/7N0AKFgPXvluJy5UzhQfbUfRL+yh4QLMY0KcK7F6 x13LbKRblEtFFwHe0eOJ4OuCSklHqbEtdUADXo2Iv4rmlHeha1M9GTw3C0ytJVFXSP73 QBSJdQM+hL6yYaqfu3IPa+Tg0UOBxDuTolOb35JWvuuGW/sBA1UiJ0YTmgURbkRwlEhK 8MgwfJ48wwpAf/98m4CVIApCtP0spVbczAVmEW+njuI9NvdPZJJPc4p545implWImjKn CMYeHr2Q6bE+cftvLDQQryS58LEVZIoi6mNEZE6rkED12knUwMPe8zphH3aZ8fMalDpD Tb0A== X-Forwarded-Encrypted: i=1; AJvYcCX2pQ9jYroJ+SpD+nqCaXj+xRlN/K+X7qtmVFRoaD/nw0fNbtrCvRLxDXf0kFGjbqqGTrmu3eJdxr9dyKuOmA0Nj00CtjDZ9HAckRPZ X-Gm-Message-State: AOJu0Yx92KZtUkqW6v2sh+5JFNf9oXOJ7zabyF8rLE+4hIqKquMZF6aL cOUOMVn1agWynbl7z7neou71vyzRQj8p7fD8PjPdhYYpC84zOLUeonFOL9RWM+P5De4oL/pHcXj 05Cfo73m2l3g4OHOo6OYMmRL75lIAvjr1MCEWqSmgE6wmUuun0tx7 X-Received: by 2002:a50:aa95:0:b0:565:f7c7:f23c with SMTP id q21-20020a50aa95000000b00565f7c7f23cmr709860edc.3.1712190278846; Wed, 03 Apr 2024 17:24:38 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240403183352.391308-1-phillip@squashfs.org.uk> In-Reply-To: <20240403183352.391308-1-phillip@squashfs.org.uk> From: Justin Stitt Date: Wed, 3 Apr 2024 17:24:25 -0700 Message-ID: Subject: Re: [PATCH] Squashfs: remove deprecated strncpy by not copying the string To: Phillip Lougher Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Apr 3, 2024 at 11:34=E2=80=AFAM Phillip Lougher wrote: > > Squashfs copied the passed string (name) into a temporary buffer > to ensure it was NUL-terminated. This however is completely > unnecessary as the string is already NUL-terminated. So remove > the deprecated strncpy() by completely removing the string copy. > > The background behind this unnecessary string copy is that it > dates back to the days when Squashfs was an out of kernel patch. > The code deliberately did not assume the string was NUL-terminated > in case in future this changed (due to kernel changes). This > would mean the out of tree patches would be broken but still > compile OK. > > Signed-off-by: Phillip Lougher Reviewed-by: Justin Stitt > --- > fs/squashfs/namei.c | 14 ++++---------- > 1 file changed, 4 insertions(+), 10 deletions(-) > > diff --git a/fs/squashfs/namei.c b/fs/squashfs/namei.c > index 11e4539b9eae..65aae7e2a859 100644 > --- a/fs/squashfs/namei.c > +++ b/fs/squashfs/namei.c > @@ -62,27 +62,21 @@ > */ > static int get_dir_index_using_name(struct super_block *sb, > u64 *next_block, int *next_offset, u64 index_star= t, > - int index_offset, int i_count, const char *name, > - int len) > + int index_offset, int i_count, const char *name) > { > struct squashfs_sb_info *msblk =3D sb->s_fs_info; > int i, length =3D 0, err; > unsigned int size; > struct squashfs_dir_index *index; > - char *str; > > TRACE("Entered get_dir_index_using_name, i_count %d\n", i_count); > > - index =3D kmalloc(sizeof(*index) + SQUASHFS_NAME_LEN * 2 + 2, GFP= _KERNEL); > + index =3D kmalloc(sizeof(*index) + SQUASHFS_NAME_LEN + 1, GFP_KER= NEL); > if (index =3D=3D NULL) { > ERROR("Failed to allocate squashfs_dir_index\n"); > goto out; > } > > - str =3D &index->name[SQUASHFS_NAME_LEN + 1]; > - strncpy(str, name, len); > - str[len] =3D '\0'; > - > for (i =3D 0; i < i_count; i++) { > err =3D squashfs_read_metadata(sb, index, &index_start, > &index_offset, sizeof(*index)); > @@ -101,7 +95,7 @@ static int get_dir_index_using_name(struct super_block= *sb, > > index->name[size] =3D '\0'; > > - if (strcmp(index->name, str) > 0) > + if (strcmp(index->name, name) > 0) > break; > > length =3D le32_to_cpu(index->index); > @@ -153,7 +147,7 @@ static struct dentry *squashfs_lookup(struct inode *d= ir, struct dentry *dentry, > length =3D get_dir_index_using_name(dir->i_sb, &block, &offset, > squashfs_i(dir)->dir_idx_start, > squashfs_i(dir)->dir_idx_offset, > - squashfs_i(dir)->dir_idx_cnt, name, len); > + squashfs_i(dir)->dir_idx_cnt, name); > > while (length < i_size_read(dir)) { > /* > -- > 2.39.2 >