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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E62EC433F5 for ; Mon, 23 May 2022 16:48:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239178AbiEWQsj (ORCPT ); Mon, 23 May 2022 12:48:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239147AbiEWQsf (ORCPT ); Mon, 23 May 2022 12:48:35 -0400 Received: from conuserg-09.nifty.com (conuserg-09.nifty.com [210.131.2.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F26F2644DD; Mon, 23 May 2022 09:48:28 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-09.nifty.com with ESMTP id 24NGlJD0027017; Tue, 24 May 2022 01:47:19 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com 24NGlJD0027017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1653324440; bh=MPCA4R4IqWHRkBoJTaSINoN0aOYzgG+YzlA/rC/ZfBc=; h=From:To:Cc:Subject:Date:From; b=kZfpt0w3P3DG2SLXPnsun3UPZ7zJyilLysw5WLLP41/wod0yO/f6/1rpEjsrFJwX4 9oUSId3Mlh+RexpiBcF8vSY9jLA9YSFZsxjSVZ33B1tJpRqCUUVEF5yb+4tIz+HmSj fSSIs5QVLIotxBdF0Xu4cv3Z0ATSfOPKa0XDor0BhY/252+wp0enEOlSQjYw4nB1ZW 0q3RbLOebCgKwanPl/B1gtYdXmA2it3Tn46vex4tyDH/mADl8EU0iPwExPECninERg gJ8klJGnULspDInuVZBGYsnBXiy6Xvympv0LPNAfIaU+NTTwK4TVn9UcKTkf/MoWXT JChD4d2BoIi/w== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Michal Marek , Nick Desaulniers Subject: [PATCH 1/5] modpost: fix undefined behavior of is_arm_mapping_symbol() Date: Tue, 24 May 2022 01:46:22 +0900 Message-Id: <20220523164626.858340-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The return value of is_arm_mapping_symbol() is unpredictable when "$" is passed in. strchr(3) says: The strchr() and strrchr() functions return a pointer to the matched character or NULL if the character is not found. The terminating null byte is considered part of the string, so that if c is specified as '\0', these functions return a pointer to the terminator. When str[1] is '\0', strchr("axtd", str[1]) is not NULL, and str[2] is referenced (i.e. buffer overrun). Test code --------- char str1[] = "abc"; char str2[] = "ab"; strcpy(str1, "$"); strcpy(str2, "$"); printf("test1: %d\n", is_arm_mapping_symbol(str1)); printf("test2: %d\n", is_arm_mapping_symbol(str2)); Result ------ test1: 0 test2: 1 Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 6f5c605ab0fb..845bc438ca49 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1179,7 +1179,8 @@ static int secref_whitelist(const struct sectioncheck *mismatch, static inline int is_arm_mapping_symbol(const char *str) { - return str[0] == '$' && strchr("axtd", str[1]) + return str[0] == '$' && + (str[1] == 'a' || str[1] == 'd' || str[1] == 't' || str[1] == 'x') && (str[2] == '\0' || str[2] == '.'); } -- 2.32.0