Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2658362imn; Tue, 2 Aug 2022 11:01:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR7U0xgaytor+MY+7RdyPDM0Td6hBPU7o6iMH6Uggrmwt5IKITv7e8BPrj6OcuxBwL+/KaiL X-Received: by 2002:a17:902:e88c:b0:16d:4364:2c37 with SMTP id w12-20020a170902e88c00b0016d43642c37mr22207612plg.69.1659463309470; Tue, 02 Aug 2022 11:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659463309; cv=none; d=google.com; s=arc-20160816; b=NwImVdBSnUZVEAYW//Qsw7S+/j2UHD5frtVZb/OChjpCXEp1A1QUHtLE3Y1gYF+Rz4 f77NOOY4cyL/+ZxFxC23h2zZ504tAbY4XtajaDB+tQMoRSLi7Vb2pJ3nzsFsUcCW79hf /iUxY5AnfiQ6RrEhe9tw9E+utOFTnLPsPVo36jN5K3iL6KxM1Q8rop4ADwAqtHvR/S1n 10nOsQMPKq9no02z+X4IUsTifkAxqZ6+LDaW2oIv15WMYSBrr+PPYlbVYSeIIck6IAXZ SD0i0ZdD3rXq76RaICvf8VPnAdqQ5aR9kl+WG9TFaCyC8JuR/rsahpN66g1cfTSK9PQ4 jcZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xMFTPfu+5zncYEkukQRG8ZpUKBpBT3nlb86KyCAQyPA=; b=wWuDf1pnvRpg/1tyuQMrI3Du+ONx3vuWZP5Cfp83XuqBlcSBQUPV4OpF2iQGvrXJ7c INPXMOXEa4mEuM9rmReFBS2TXr94ECQ/yMaOvDoTyD01bwMsA3OJLo1xAj7uj/0Ols4M DjSl5F+VcPFLhQEsPtm7ipgpMN3lrvcRrz9H8Vo36Jhma+ylcP+hNnOsyPxYDlUEfCIA eaIXUq2qpzo2gMs+oFgb9Y1+iUclSB8yJ/LF9YUyY99yndQlf+iw6nLasJfmDH/tQxzk 5QYrCjn8zaF0MPgOo/VoSH+zuIJrwQBdRlpzBpyvpYcFbydKXSUakwjKpLm5U7IA1Jum P5Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=aQoMJrSs; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k20-20020aa78214000000b005283a29e7b7si14997967pfi.115.2022.08.02.11.01.35; Tue, 02 Aug 2022 11:01:49 -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=@google.com header.s=20210112 header.b=aQoMJrSs; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233461AbiHBRzz (ORCPT + 99 others); Tue, 2 Aug 2022 13:55:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbiHBRzx (ORCPT ); Tue, 2 Aug 2022 13:55:53 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 791C61EADC for ; Tue, 2 Aug 2022 10:55:52 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id s9so10455843ljs.6 for ; Tue, 02 Aug 2022 10:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xMFTPfu+5zncYEkukQRG8ZpUKBpBT3nlb86KyCAQyPA=; b=aQoMJrSssxzauOdbFrB9wScBW+nXxpw4uqe3xSTFfXbWSUB1ZNa8czyknKQsXH3Gpb xvHwm+NbqgRm688vJvTJ/7TV3Kq58FX3szhuh9gSJL5KWIdhYyxILQfTAKhJkR4Tw0sU JDqvhMSSX5F7JfSovXlE+rWOpUIh0XX7jURrhu7/4Afdz0e4EcVwfBPgK/PgicV7stZG vMrTnPaDxE68+gmVB1uj7YVPOYL3gqA9J68ILuPaj6J9DKiR3Dc1VQv11QZEawXNmosA LR5w/h3HkK9B/DSSms2J0eHdRMcCiEKnfDzAIsIvMuiBLUoIJ1b5ewH54CfDoxq12RJ2 qgMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xMFTPfu+5zncYEkukQRG8ZpUKBpBT3nlb86KyCAQyPA=; b=rJAejgjtJEluUkxg2EC+7irhx9nEaI8Sj4gvfJX28r/jr4K3safdtZxPTNaq6G4Uvi 8E2IqeIsm3aCy+N2G01LsOw2vqOTuJFJ8VGXg/vutRlDX7qgwVnSXd24yZ3rRhCdWQLC Q58TkuPAy2MQpcDShFWr+VqV5XFdFhZEZ3ALaNRTAQ38tZFWHYQT631pxx/7CSEWSgTR rAC36sLzsDR8jEJ6ar3Xf0zU8IVRnm1H++yJk21nM2qUf+zcusy2+v0vhGSpZkR00HYj rMOkXQywCrgslo17m7Wxv2eeqoXZQ29JJMcmPY8dEbpNKnwHlT0IZHWBt3ULC73NpddZ 56aQ== X-Gm-Message-State: AJIora+yquQnuIwlfcAv5KznhODapA6F1eHDAP+xH7LOgWXX72qHKcZU YRBT46n103dVyWO7yu1yHq4eok6B44ynMWQARMzvB8xlOMCgKg== X-Received: by 2002:a2e:920e:0:b0:25d:ed6f:e66b with SMTP id k14-20020a2e920e000000b0025ded6fe66bmr6558873ljg.103.1659462950708; Tue, 02 Aug 2022 10:55:50 -0700 (PDT) MIME-Version: 1.0 References: <20220730173636.1303357-1-masahiroy@kernel.org> In-Reply-To: <20220730173636.1303357-1-masahiroy@kernel.org> From: Nick Desaulniers Date: Tue, 2 Aug 2022 10:55:39 -0700 Message-ID: Subject: Re: [PATCH 1/3] modpost: add array range check to sec_name() To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Michal Marek , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Sat, Jul 30, 2022 at 10:37 AM Masahiro Yamada wrote: > > 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 I don't mind adding this check; though if it's anomalous I think we could also just print to stderr and abort. I would prefer Elf_Sym over unsigned int though. WDYT? > --- > > 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 > -- Thanks, ~Nick Desaulniers