Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp217943rdh; Mon, 18 Dec 2023 17:31:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkwx2N388syycnghpOj5jG740bGLzj9qEY2uYUlFT7D9NE7uf4mJKfGo4ozHDmlr39OzV9 X-Received: by 2002:a9d:7981:0:b0:6d8:5693:4dbb with SMTP id h1-20020a9d7981000000b006d856934dbbmr15210369otm.38.1702949512195; Mon, 18 Dec 2023 17:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702949512; cv=none; d=google.com; s=arc-20160816; b=iUNAQErdqFuAr7BBubyXqFlD2707CvOKvSK1KokOAVrsleBQBchGSlozsNyHcSbM/P t80RRD9frc9yuoUpqp3IMSYgycBxyZ+UKnkOgbMRIufYcsQbUK5UqTht2kwHULh9a0+s kJipY0QC8SFQon6Qf99Y1Szq8rKPO5t9K0l/0hv0i58PtGrNCr84u3iXPXSWDxPd/MsP NiBqrVzsM5DzxhH++GZzyh6A9PNQAbEq7j4TmrJHdEGE2in0HyuOCN2Fhy+EffaZp1hh SY61CsQfPsZep4RHanuM9vvHPXLnnmj/iNaOiJyg3JcFn57/TRZ5IwRHYytNYYHctH+s V3Ow== ARC-Message-Signature: i=1; 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:dkim-signature:date; bh=Og+ebVjdtObkh/9hZzSUL0YvYnnGqKkNV0U89WgdwhY=; fh=b4yDpRzQZjxnD1UgrAWHsnqbJi+dpOTTrJVVaKbGA28=; b=Sx8DFYqIQz94xZ8N9uOAc7iNelySeyzOXUA79p6yoxj0pJ4AQvBSR6Q7F/sAdgDgAl UECAD36g4JrQu3Jvtn5v8wjzm9Je6nJZiqp3JLm45jcLQujSaOAOeXgElumWIaPb9IDf ByLcvULWid0bLVopgIkm78kpU+0gq4CMftayEpY4JjbpmoZquS8bOppGn/7tQDmQX84Q WrsfvAawUPqEuXc5EVq2ybfUBRc2mN2xyMm7/jWWMe8XF6D/yaUVzXOmBBmxLANlQbpo 8ZsKb7/nSs/TUhVcPopxHBY7K9PW5zZLjdmWGgXOG4ZqB263c78rRDCgo6OFvElwdHCY RdsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="P1/rkGsP"; spf=pass (google.com: domain of linux-kernel+bounces-4559-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4559-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s205-20020a632cd6000000b005cd6ad1ca3asi6085907pgs.195.2023.12.18.17.31.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 17:31:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4559-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="P1/rkGsP"; spf=pass (google.com: domain of linux-kernel+bounces-4559-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4559-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CF28C285D7D for ; Tue, 19 Dec 2023 01:31:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3AB017D9; Tue, 19 Dec 2023 01:31:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="P1/rkGsP" X-Original-To: linux-kernel@vger.kernel.org Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 5CC2315B1; Tue, 19 Dec 2023 01:31:42 +0000 (UTC) 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 Date: Mon, 18 Dec 2023 20:31:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702949500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Og+ebVjdtObkh/9hZzSUL0YvYnnGqKkNV0U89WgdwhY=; b=P1/rkGsPhU373ucv7wBZ+fBBFamyyw9UmxNMe3CHvxWKumP7w5wBjacgwCRn/7dWM7qK62 cobI4lsHTx2SHyXRikmlUWgbpUKU3Kn+LzWWV4Z19Dwd+ZjeMxXiK7WuujbvK+r+2pbsdR IYDc//4ot7IL1UZj1xwx8G4kYVVnOKM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: "Gustavo A. R. Silva" Cc: Brian Foster , linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] bcachefs: Replace zero-length array with flex-array member and use __counted_by Message-ID: <20231219013138.c6jo33i7oowk4vgr@moria.home.lan> References: 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: X-Migadu-Flow: FLOW_OUT On Mon, Dec 18, 2023 at 06:24:53PM -0600, Gustavo A. R. Silva wrote: > Fake flexible arrays (zero-length and one-element arrays) are > deprecated, and should be replaced by flexible-array members. > So, replace zero-length array with a flexible-array member in > `struct bch_ioctl_fsck_offline`. > > Also annotate array `devs` with `__counted_by()` to prepare for the > coming implementation by GCC and Clang of the `__counted_by` attribute. > Flexible array members annotated with `__counted_by` can have their > accesses bounds-checked at run-time via `CONFIG_UBSAN_BOUNDS` (for > array indexing) and `CONFIG_FORTIFY_SOURCE` (for strcpy/memcpy-family > functions). > > This fixes the following -Warray-bounds warnings: > fs/bcachefs/chardev.c: In function 'bch2_ioctl_fsck_offline': > fs/bcachefs/chardev.c:363:34: warning: array subscript 0 is outside array bounds of '__u64[0]' {aka 'long long unsigned int[]'} [-Warray-bounds=] > 363 | if (copy_from_user(devs, &user_arg->devs[0], sizeof(user_arg->devs[0]) * arg.nr_devs)) { > | ^~~~~~~~~~~~~~~~~~ > In file included from fs/bcachefs/chardev.c:5: > fs/bcachefs/bcachefs_ioctl.h:400:33: note: while referencing 'devs' > 400 | __u64 devs[0]; > > This results in no differences in binary output. > > Signed-off-by: Gustavo A. R. Silva Applied