From patchwork Sun May 19 09:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 797998 Received: from smtp.smtpout.orange.fr (smtp-21.smtpout.orange.fr [80.12.242.21]) (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 7C19CC125; Sun, 19 May 2024 09:19:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716110380; cv=none; b=KxAm2z1uayq2t7cefKCxAQ0b3wZVD0MQvkt8o4SO6p4tGhOXk36DZ+bTdVyUVE+jKDkVGA+TAHMEPjEMCM4zUZXyvB0g8YIOm9y2rs9AnmzpxrQVqwBT0ZTk6S8+f8bHM1YkhlPv56GTG9TCB84/HXrptEYi5hvGQQjFWf8UFcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716110380; c=relaxed/simple; bh=2Io+Fz92zJ104X+y+nqXRgFvu2MtCDcDNZhKBzNDC5E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HlTqm7ne3SVbGwY+Vqhe/YliMdLZGhZ9+EyY4B5BIPSbyqmzc3vAaJz881EI5c0TpKLjicJa/cr5PNIiSPRJ0jTPBsDGjikB3/0pZZhwhYWG5PqEmO1vO/xTlASeHne6LsZeVlL0xJJWRJYuBw5V+KDRjPTjGu/JnH8onV2HqYo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=Fwg2QKOm; arc=none smtp.client-ip=80.12.242.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="Fwg2QKOm" Received: from localhost.localdomain ([86.243.17.157]) by smtp.orange.fr with ESMTPA id 8cYSsFC8hNQ4U8cYSspY8i; Sun, 19 May 2024 11:10:10 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1716109810; bh=ZiwYqa/OT+egvt96+ug0V0xJ+qb/MMnvIJ/vMwb2q84=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Fwg2QKOmzOVxipJAi1QrNN07ZhrxdXAZDJsyPMcP9DtpkEFUPxtXBpRk2xkAqvwkz rVaYBKpWurpPvr706qcDKnWpCc6dudb6EWXjESZSpzjlUr/uW1/ONwJHb9DhESSTQK 9mkuAvDOhMHVXLZ4JTLwdzUaNc2LaxmSDTv+7jx+ZhI36EJgOkVJq29ig3RP10BDao LIZ3f1GRX1jfan4mcTyNvRfxWOO7pjr5VY5dXRXXLAou+aJdYnP+f5UsXfnAoOfFjG G8uhXfYL/Hy7U/KqVMRsK0AeTaqeBwydUR/VkfbagFHmAn+F2nXSvUP+jr5Qf8fU6s mdzzUL+H1IN9Q== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 19 May 2024 11:10:10 +0200 X-ME-IP: 86.243.17.157 From: Christophe JAILLET To: Ilya Dryomov , Xiubo Li , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , ceph-devel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 1/2 net-next] libceph: Use sruct_size() in ceph_create_snap_context() Date: Sun, 19 May 2024 11:09:58 +0200 Message-ID: <5b7c72bdb52703bbfa5511ed500aed4babde1308.1716109606.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use sruct_size() instead of hand-writing it. This makes the code more readable and safer. Signed-off-by: Christophe JAILLET --- Compile tested only --- net/ceph/snapshot.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/net/ceph/snapshot.c b/net/ceph/snapshot.c index e24315937c45..7363ccebee99 100644 --- a/net/ceph/snapshot.c +++ b/net/ceph/snapshot.c @@ -28,11 +28,8 @@ struct ceph_snap_context *ceph_create_snap_context(u32 snap_count, gfp_t gfp_flags) { struct ceph_snap_context *snapc; - size_t size; - size = sizeof (struct ceph_snap_context); - size += snap_count * sizeof (snapc->snaps[0]); - snapc = kzalloc(size, gfp_flags); + snapc = kzalloc(sruct_size(snapc, snaps, snap_count), gfp_flags); if (!snapc) return NULL; From patchwork Sun May 19 09:09:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 797792 Received: from msa.smtpout.orange.fr (smtp-77.smtpout.orange.fr [80.12.242.77]) (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 9C454241E7; Sun, 19 May 2024 09:10:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.77 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716109833; cv=none; b=abwgNEvQr2tUW8bG3U96qz1CYRdSTn79yo6FlR0zUCNRIWvAiO+biYWzqvn4KWN8zYG2EwJp61rD98LoOkVtGdbc192Owb7nZ0EvDxhWXSY+0aNImnIiswriKAuTothr6wm1RqGo6aMPJUbhju6ioJcSWDPrl7Pq52kaIF/a4CU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716109833; c=relaxed/simple; bh=WHLI54myjQZgi0GBCy9D+0xHgarTdc8QkTWV2HYfM/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b9fi5D7ChqClWT3i+Q6b6d5gmB6akvKVYDgiObLHPWdwmz+r31ON8ZMI02wkA2X3tf2X4QMElujOT7GGEL3jK2ARklIZRaopD4tD0uoRVsBuDxKmLNA9aOUbxwKpiNA0CTvlZKDnUnEmkhPMpmvy+i7rAcuu8r38gcqNLuLKdNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=okS4Sb9h; arc=none smtp.client-ip=80.12.242.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="okS4Sb9h" Received: from localhost.localdomain ([86.243.17.157]) by smtp.orange.fr with ESMTPA id 8cYSsFC8hNQ4U8cYespYD1; Sun, 19 May 2024 11:10:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1716109820; bh=BuzLzcGApaGthL63ihFJK2+ain4oC/YEb1ozPZvoVBw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=okS4Sb9hoEuVjb/kMR4hDnZ7f6paQP6y+KGUUnGBCL3cEN9W2FRGXwRMKCtQiu7j8 GwFGm+DxRbnK/KEb4xhXYM0qZB9XEHTgZWBXftEXsIh7Bi+Wr+Cf+N7EXmWrt2XmB2 6D42KRIi34gw9NqHAD8RVWjp+i5Em6sh2J+lfdDhNXazdeaJvaBQ5NayMjaeDQeamH OtHdnCMjSOqdnF77nvm5QrzWz5uEE/9Erjdid7uya0HZycP+Y17WT6q4DON/3BeJX5 /ZK9tzEykO9ORHOTdCr8HRdYPBdI7+glqOV4CBYU0npR9mRG8LI4B+1IHlgj+eB6M2 gxMgDGkCLoadg== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 19 May 2024 11:10:20 +0200 X-ME-IP: 86.243.17.157 From: Christophe JAILLET To: Ilya Dryomov , Xiubo Li , Kees Cook , "Gustavo A. R. Silva" Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , ceph-devel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 2/2 net-next] libceph: Use __counted_by() in struct ceph_snap_context Date: Sun, 19 May 2024 11:09:59 +0200 Message-ID: X-Mailer: git-send-email 2.45.1 In-Reply-To: <5b7c72bdb52703bbfa5511ed500aed4babde1308.1716109606.git.christophe.jaillet@wanadoo.fr> References: <5b7c72bdb52703bbfa5511ed500aed4babde1308.1716109606.git.christophe.jaillet@wanadoo.fr> Precedence: bulk X-Mailing-List: ceph-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Annotate the 'snaps' flexible array in "struct ceph_snap_context" with __counted_by() so that additional checks can be made, if enabled. Signed-off-by: Christophe JAILLET --- Compile tested only --- include/linux/ceph/libceph.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h index 4497d0a6772c..485efc8837d5 100644 --- a/include/linux/ceph/libceph.h +++ b/include/linux/ceph/libceph.h @@ -164,7 +164,7 @@ struct ceph_snap_context { refcount_t nref; u64 seq; u32 num_snaps; - u64 snaps[]; + u64 snaps[] __counted_by(num_snaps); }; extern struct ceph_snap_context *ceph_create_snap_context(u32 snap_count,