Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp443428iog; Mon, 13 Jun 2022 06:06:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEsnahd+SZHgLZPE05a9N2DdteY7pprzEqThh+IfFGC1j7RO7efoDw82g/96SAxBTakRDw X-Received: by 2002:aa7:d285:0:b0:42d:ca4f:a046 with SMTP id w5-20020aa7d285000000b0042dca4fa046mr65687790edq.354.1655125603451; Mon, 13 Jun 2022 06:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125603; cv=none; d=google.com; s=arc-20160816; b=q69kG8rFMdcJ3JIdZXiiIA5t6ASLD8gt2M5UFYXilRIwsueDaXc9Ya4krZxPAVM9Mu Cedzz3BDzQbayc0rJpizbDEKfcMzV/LPy3KUYfbclVv4glKywh6w6XmccfxZ9tNQj9B+ AR2BepCx+BmrN9XMZk9LKFZl9/lDWhUbH95BEDD6Y73kh7lD3l88U7DNxs5SXbQDdO6d NseYt8jihVQyCt+cY8iUvUZtn7eBWiamrHYOmuCQvy9Pz+Z/RNUr8uGxVkZNsVfuf2M3 6pX9z6XzdlffwsfVHO2+rN4uWYlwstrjGGl5rDPzLGtC1/Nbe5V/0KVrfyoCiINqlKRp W2DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=A6nx1VHzXsarpDVutTr83oxpxYRULJop8Qok3wkl5LY=; b=iudsWFDCynRxXib7JU66PWD84wf3b1ftFbj+rJgxeBeRTCYBhDzW3GDItF0RNNUQud XGavCLcVdjBJ1kJT1SucfrKiOASM4sbx2mCAbObxIEF7QRkTdQFFZrsNHGU+zhTNuutl wByXYh1bjc16ndr6sWClJAmFbHXM6woCqHZW9jXDYvs76VmKExXHSNj3i9tQtrl2DHmW RJ76Q+ztFtAiKaLmEgMWCjX4kedPv5eA/xjnwnRgmLLlVxZIfu5MmG3hxXKWnG0L25wr 1i7U2M3Dp7OmfD1cecm7XYUZGebhAGhHDjdsjE5Xs/7c0L7XNlcaFs5LYVE+S3guzeeC KIog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mXdPpPTe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 22-20020a17090600d600b00718bebeb259si3221191eji.696.2022.06.13.06.06.09; Mon, 13 Jun 2022 06:06:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mXdPpPTe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356965AbiFMLwX (ORCPT + 99 others); Mon, 13 Jun 2022 07:52:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357558AbiFMLqV (ORCPT ); Mon, 13 Jun 2022 07:46:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 562EF13D7C; Mon, 13 Jun 2022 03:52:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 96F5161259; Mon, 13 Jun 2022 10:52:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB396C34114; Mon, 13 Jun 2022 10:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117558; bh=oFxGFstiGXD34FENzq7tY+9mjgtJY0fkcntZ8gaXq64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mXdPpPTe2phoWZM1eN99ihdRfFudM7DcY9tofqnaNGmUqjM75d6KbQpSYtWq/DWhu 5b6l1bON/fhYP9UDVzxxS+di9Pcmv97eiD1vcgu8QeHFVmCXmlyiS0nk/YME+BnFei QuBYe+028i14ikppMSaI+dyQSFAX6Aj6V1WF37yw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Nick Desaulniers , Sasha Levin Subject: [PATCH 5.4 390/411] modpost: fix undefined behavior of is_arm_mapping_symbol() Date: Mon, 13 Jun 2022 12:11:03 +0200 Message-Id: <20220613094940.365954803@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masahiro Yamada [ Upstream commit d6b732666a1bae0df3c3ae06925043bba34502b1 ] 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 Reviewed-by: Nick Desaulniers Signed-off-by: Sasha Levin --- 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 74e2052f429d..59011ddf8bb8 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1283,7 +1283,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.35.1