From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58487C54E8B for ; Tue, 12 May 2020 08:03:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 352652075E for ; Tue, 12 May 2020 08:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589270617; bh=PFaK79n0IGBPF3VDpooRxhdJuxEffJZ89L4xjaMOT68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=rh4gpk6QBdkwbnqBtPk15KFEy17YYCDaFaM02ZUW1eEwASch/syQH/1oiONIReGNN WwBYzNT1NpYtNl8B/RhKA+eam8yZbC4J0V/q6aVpy8WBiIRgQPouPXYIj206KRaVkO yp93G1MwycWBYNha/hlDDGSPD79vDMoaHN1oXLWM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729165AbgELIDg (ORCPT ); Tue, 12 May 2020 04:03:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:57562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729145AbgELIDf (ORCPT ); Tue, 12 May 2020 04:03:35 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 27AE520733; Tue, 12 May 2020 08:03:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589270615; bh=PFaK79n0IGBPF3VDpooRxhdJuxEffJZ89L4xjaMOT68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dutZ4xkwV85H4IRe8e1Ka9PKT+tOOFXQLCTIidZxaMPCtWcXq5qKVy1i5AhDT0m3I ZExss6O395cVblLEe0K0f24Z1Cq4EWu8rLA8AMU4MOo+0D0euSpwJT691zagNYhXG4 x3lrI+QyM2VBEwDxSlE4H6xWCXPrL9S0xa258ETk= From: Masami Hiramatsu To: Ingo Molnar Cc: "Gustavo A . R . Silva" , Anders Roxell , paulmck@kernel.org, joel@joelfernandes.org, "Naveen N . Rao" , Anil S Keshavamurthy , David Miller , Masami Hiramatsu , Linux Kernel Mailing List , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Ziqian SUN Subject: [PATCH -tip V6 6/6] kprobes: Replace zero-length array with flexible-array Date: Tue, 12 May 2020 17:03:29 +0900 Message-Id: <158927060954.27680.8740399526358942446.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <158927054236.27680.18209720730136003586.stgit@devnote2> References: <158927054236.27680.18209720730136003586.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gustavo A. R. Silva The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] sizeof(flexible-array-member) triggers a warning because flexible array members have incomplete type[1]. There are some instances of code in which the sizeof operator is being incorrectly/erroneously applied to zero-length arrays and the result is zero. Such instances may be hiding some bugs. So, this work (flexible-array member conversions) will also help to get completely rid of those sorts of issues. This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] https://github.com/KSPP/linux/issues/21 [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva Acked-by: Masami Hiramatsu --- include/linux/kprobes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index 645fd401c856..53c4f2c1d658 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -161,7 +161,7 @@ struct kretprobe_instance { kprobe_opcode_t *ret_addr; struct task_struct *task; void *fp; - char data[0]; + char data[]; }; struct kretprobe_blackpoint {