Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp995670imn; Sat, 30 Jul 2022 10:58:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Y2UKk0QvkCPdC42z+jN4ZakjynQL0IxCKCQOCaPhdquz3RHg1NVVebir/iPSK6D7DB5qg X-Received: by 2002:a63:d24c:0:b0:41b:b2b1:fff9 with SMTP id t12-20020a63d24c000000b0041bb2b1fff9mr4534003pgi.246.1659203921241; Sat, 30 Jul 2022 10:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659203921; cv=none; d=google.com; s=arc-20160816; b=0rneWz7VkPbQ7gMnKnTYKZ9ywwM4f/HTnrLXj+5z3Umjbq9L2qnEhdwI9mdrKCI3BO DOD5Lqzf3Bk9/6CnHxHeWj8wnXyjK8Eq3qA4HQp0GyVC8Q5LHFCdQ8ErmBOuuNp1toVv XYrM4i5bkEXWdE0dp7NvPeHURXgmsa6NmjRRe/qsRPkOmD7D/mssIgPuyFySmHaayv91 8iIikRTMkhMm7Ma5bkFPv859gmXyuLVJ5eY115i2f5YlcEBoPtvT16ilKk4iFSQRUwN8 fllZfwT2AuWwEB46QwEpi64ok51itJVx37onzd2IlHsc1RVfNhvU4VrrAxtBGAzD3is5 dbQQ== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=s5i4NN8QoFKQRwc5evurXo6JXtv34LY9d/GuIT5gPKU=; b=xXCwStWQGZen4Tk3p5AQlpZf1NDUa6r7A1ctuEgT7l+Y6o1TU8X/NiSV97DBdj4pLD DGLh4cQswMzVz9RVDUw1XZAS5ZaCogLJvwMk+J0okHAYV68gDxmzRFojPqmWCugx+XRa BBA5d4DocG5cBSSWOjva1vU7PB4HfRja6fgeOkB5UelNbM4ssM3q1PHIg+A+6X67IAAL L01S/7sLt+rhLUMsosMtaBam6f+0ZoZV1Dwj3v0AM274B2hWLGv9cqe354dAYBWxIjG5 vHChjTjHmU7wZEGU3JP7NUBMzUAiEZMiIVr6DdrIfl+Zxfwm6Oy7EXXuQ6EnTHADsAsX CKOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="NnfzF9/L"; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y18-20020a170902ed5200b0016cae200f99si7159264plb.330.2022.07.30.10.58.11; Sat, 30 Jul 2022 10:58:41 -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=@nifty.com header.s=dec2015msa header.b="NnfzF9/L"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235424AbiG3Rhv (ORCPT + 99 others); Sat, 30 Jul 2022 13:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235014AbiG3Rhr (ORCPT ); Sat, 30 Jul 2022 13:37:47 -0400 Received: from conuserg-10.nifty.com (conuserg-10.nifty.com [210.131.2.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E8A15A00; Sat, 30 Jul 2022 10:37:45 -0700 (PDT) Received: from localhost.localdomain (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-10.nifty.com with ESMTP id 26UHad9Z015991; Sun, 31 Jul 2022 02:36:39 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 26UHad9Z015991 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1659202599; bh=s5i4NN8QoFKQRwc5evurXo6JXtv34LY9d/GuIT5gPKU=; h=From:To:Cc:Subject:Date:From; b=NnfzF9/LtuTDbNwcvojr/Ivo4XVgeFXRmupqWWDmfNGaZqhuUcvrVKIN5yy2giVrr Bvecxcxl4nd+RO904sAA28IDUyAwH08XaZxchPorsqiiiL04kx21ocKMIVlkTJNewR 3DAYgPDZM/QdnlkV/M/YslS9SYr4u0H/6BSKGGmK6QVJLYhslFNvw82fuXBEvazR2m eg5Ow2UYc9y1I3m/vvGNeM59Mm1Y22/5Nb4BRY++3f4Tb9IkYGGDe27Vj/vlF23CP0 QA0KR8QGypvLJzqSXVnK8/rRyz3w/GqhIn0mN5/+ce7BqCT9ailLvMOllthtDpeLAn 1uELQNo35+y8A== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] modpost: add array range check to sec_name() Date: Sun, 31 Jul 2022 02:36:34 +0900 Message-Id: <20220730173636.1303357-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no 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 The section index is always positive, so the argunent, secindex, should be unsigned. Also, inserted the array range check. If sym->st_shndx is a special section index (between SHN_LORESERVE and SHN_HIRESERVE), there is no corresponding section header. For example, if a symbol specifies an absolute value, sym->st_shndx is SHN_ABS (=0xfff1). The current users do not cause the out-of-range access of info->sechddrs[], but it is better to avoid such a pitfall. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 08411fff3e17..148b38699889 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -336,8 +336,16 @@ static const char *sech_name(const struct elf_info *info, Elf_Shdr *sechdr) sechdr->sh_name); } -static const char *sec_name(const struct elf_info *info, int secindex) +static const char *sec_name(const struct elf_info *info, unsigned int secindex) { + /* + * If sym->st_shndx is a special section index, there is no + * corresponding section header. + * Return "" if the index is out of range of info->sechdrs[] array. + */ + if (secindex >= info->num_sections) + return ""; + return sech_name(info, &info->sechdrs[secindex]); } -- 2.34.1