From patchwork Mon Nov 4 23:42:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thorsten Blum X-Patchwork-Id: 2006581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=a5P5+jZv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=ml7h=r7=vger.kernel.org=linux-ext4+bounces-4950-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xj7MV0q5Xz1xyM for ; Tue, 5 Nov 2024 10:43:33 +1100 (AEDT) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Xj7MN5Wp4z4x04 for ; Tue, 5 Nov 2024 10:43:28 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4Xj7MN5P52z4x8d; Tue, 5 Nov 2024 10:43:28 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:40f1:3f00::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1730763804; cv=pass; b=deJawwc91r3XUCRpAT/8+WDBWHid0G1VQB2jkavCLtCNcNGyXJLOWWAmklYOUXH1VcpAohpUl4PAsAsFcbWRGs+SZdG5WGrc8I54nuJ4qzbzu9U89qFCJy8C3QkpNPvxfaNUpktpi0R9z3n6rs/lH15UiMwp2xabsAzqaTIunaPCW3NBvXPBQKdSb/dHDGWwuegvIEPrmoh9xWjyEztodRxIYR1Zk7NNBhTnAfaHzv0diGygydWOohJMg5sJ7693ArV0CYNE32DMoO0O/HBEBlcn63fw7QTY/FKs+4BRzvXKuOZp9eL7lJJSaB1N2Q9kt6cHszHgj0Il6fbANVjALg== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1730763804; c=relaxed/relaxed; bh=WupKgLk/g34nk7lN15EZ9LyedA501TFFTjkXVizzcRg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kBhFxo/3B1Z/GJYZnYiZux6vtGRZ3vxEEFUykwUZlATa/3I1WTpI1kmA0yGYY91KQHzybGPL+JXLHDz/m990F+EnZubKdcuDH2MzCMC2zKNN4YIKiSb/hX1NeOHAwKfWhUda7ccOikilRZI8smcFLSBZhgB5L2RbinSWw7bSI6IA28nXc+mg7v48Aamf5IuceVrE5vErALbSMeV7a9ILBYWfmD4vfVK3safts/5loIsnU4nCM0ixetyBv4wZGI+sCxbD3ZUKvNsRZ8PpGZGRmzb7OR7bqxGOCK+SdUCH8qbQVcK2XWOMKXkHE6EfSCLD/P7SRM58rWh1zEKG3TgPHQ== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.dev; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=a5P5+jZv; dkim-atps=neutral; spf=pass (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4950-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=a5P5+jZv; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4950-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Xj7MG5h61z4x04 for ; Tue, 5 Nov 2024 10:43:22 +1100 (AEDT) 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5D438B2192A for ; Mon, 4 Nov 2024 23:43:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1963E1FDF90; Mon, 4 Nov 2024 23:43:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="a5P5+jZv" X-Original-To: linux-ext4@vger.kernel.org Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) (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 8C593188703 for ; Mon, 4 Nov 2024 23:43:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730763797; cv=none; b=accXJun6ddY8lymw0nnhq4aBZnPi72kvjqW8R0PeIrs0NeHDpXP8WqNVCJFhfAI5BkWeVRhkW5JNEBZxs2zHs13VZnpItuLjHA5DDOUhvs8AEGMLKoVIkDQ1NoyS2VbcJGtNCGQ+E1GPgsE2hnK1bOzJP4vqThN51SZ/AzSO250= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730763797; c=relaxed/simple; bh=NTrgsxER1+7QIxrTxfrD4cJG/eY1xGd/3xVLkEsiYsk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dtcVkpqGzqp8C/n03jw7UfSz7EeDH5aFH3U58Q3dJactYhlfgI+WUfEegCEcyxDoZZ3/C6qzvFkFq8vT6uwh6m0SPLlgRUKKI/4QXx6805r9oFUotI9lNz5dud7ceduG0tVF9IJlXwHStZypzg/YbhWNTuKnZp/CiJbzdTh4jJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=a5P5+jZv; arc=none smtp.client-ip=95.215.58.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1730763793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=WupKgLk/g34nk7lN15EZ9LyedA501TFFTjkXVizzcRg=; b=a5P5+jZvnyU48j6Ljz71yQn+KJB3NZfwIUkHGy2kDvytoxVm8zYJjHOJRoZ9/EXn0JDaSt AoK7fEfbpIUaS8tMaSkO2DBpQsVCJ9vpuJ4oYe88XYcp445bRT4TU0gZocWeEqHtYToB/x E5ZAostBI7ZH+h6SK3NWRlHIms0dtOA= From: Thorsten Blum To: "Theodore Ts'o" , Andreas Dilger , Kees Cook , "Gustavo A. R. Silva" Cc: Thorsten Blum , Jan Kara , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [RESEND PATCH] ext4: Annotate struct fname with __counted_by() Date: Tue, 5 Nov 2024 00:42:14 +0100 Message-ID: <20241104234214.8094-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-3.2 required=5.0 tests=ARC_SIGNED,ARC_VALID, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DMARC_PASS, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on gandalf.ozlabs.org Add the __counted_by compiler attribute to the flexible array member name to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE. Inline and use struct_size() to calculate the number of bytes to allocate for new_fn and remove the local variable len. Reviewed-by: Jan Kara Signed-off-by: Thorsten Blum --- fs/ext4/dir.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index ef6a3c8f3a9a..02d47a64e8d1 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -418,7 +418,7 @@ struct fname { __u32 inode; __u8 name_len; __u8 file_type; - char name[]; + char name[] __counted_by(name_len); }; /* @@ -471,14 +471,13 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash, struct rb_node **p, *parent = NULL; struct fname *fname, *new_fn; struct dir_private_info *info; - int len; info = dir_file->private_data; p = &info->root.rb_node; /* Create and allocate the fname structure */ - len = sizeof(struct fname) + ent_name->len + 1; - new_fn = kzalloc(len, GFP_KERNEL); + new_fn = kzalloc(struct_size(new_fn, name, ent_name->len + 1), + GFP_KERNEL); if (!new_fn) return -ENOMEM; new_fn->hash = hash;