Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4411395pxb; Mon, 21 Feb 2022 20:44:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyYTxdogIYx2GcOoWpR45OVNB9dZ2hOpvdlXZpriPshMTBeVpDXf2ELBHma+YZj4B3sMZU X-Received: by 2002:a17:902:d892:b0:14e:e074:7ff7 with SMTP id b18-20020a170902d89200b0014ee0747ff7mr21515110plz.29.1645505075159; Mon, 21 Feb 2022 20:44:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645505075; cv=none; d=google.com; s=arc-20160816; b=knQqBAVVYJSzP+s99qMysJ30GKtgXUcdx5p3HHGav2YYOqnujvlT+vAvevEmFB8FCL NYHrDQFZKwm6RoobmEDMxZ8lTaAJZycyUMjSSxx4gUlxbIcL4rookf/h+oQlZ985vIW9 ku0nKrdjeMGHA7uOj6oeC5k9t1AFa3VeGUGjE1RCIKAVnvVaT7gHdNo6aZC8daeT0Sez j53uQISqZZzfrwmsgrKKOcCgz70Yb8ZjohltxLRx9nqHJpsUpw2Lh7LebyEKguFgjKR+ 6rnEkuCK9M7eltFCIomYqMlZskvo3u7MUJLSpjnUT15M2fKYaUobdeNvEU/9d5/Z/sOG J8cw== 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=gNbtENvgPGvY+ECF4x7JuH0D3pfjzmMT6g44TZ0Za+8=; b=w2BjZUsmZYQqYE3geuSfvH5NEK77E0fCywhh+lL7JADcgqGm01ZN7OEw6YZ+7Lntns tlQXFolUKe40FfBURh6RQpDyeLISOADQEAdWJIM/Wg7U+w7xIhDcfb1iQ07+PPsJevSq dossvhBDEJbsGesyaxGSffCfCuDmKObO8ocPmaKb4Un+fdR5BpvgBbW2ACiHj8IVE17N NNh8t1BBHlYVW5XMDvMacgrAqesh1qu2aOUg83dLwPAc+huWqztcRx/RJnCz4+idc3lg Sd5g4iOGxxKHeOhnwGRANo11s6n65MS1Arr6Kv/8kpF6hUWY+rLhqSG5/Tz1hAhPpkVl Ln0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Soz3arL+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q36si4011654pgl.872.2022.02.21.20.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:44:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Soz3arL+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6CCB713FB5; Mon, 21 Feb 2022 20:28:29 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347679AbiBUJIT (ORCPT + 99 others); Mon, 21 Feb 2022 04:08:19 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346961AbiBUJDF (ORCPT ); Mon, 21 Feb 2022 04:03:05 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15ADE2CC9F; Mon, 21 Feb 2022 00:58:25 -0800 (PST) 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 E81C361207; Mon, 21 Feb 2022 08:58:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4A18C340E9; Mon, 21 Feb 2022 08:58:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645433904; bh=hpxen5vihTO55Q6aW24d9qk3pSPgtuGSQEi6irhJ6ys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Soz3arL+gGmMuP4z55Nro/vmjKWRyZ+Xg/ks0545pR+Q4wy7Uts5lW2VZSS6NBBVp ZsQoqN/eOOZbr6/1viie3f/YwxmoYInKHjCFxE3vYgZaQq+04M38DG6L4ABcXb3Vt6 q85Y0mDiPPN9HlOgpHtLtH1IucwaAnkFEt4BDPno= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Ard Biesheuvel , Torsten Duwe , Amit Daniel Kachhap , Catalin Marinas , James Morse , Will Deacon , Stephen Boyd Subject: [PATCH 5.4 25/80] arm64: module: rework special section handling Date: Mon, 21 Feb 2022 09:49:05 +0100 Message-Id: <20220221084916.411809014@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 From: Mark Rutland commit bd8b21d3dd661658addc1cd4cc869bab11d28596 upstream. When we load a module, we have to perform some special work for a couple of named sections. To do this, we iterate over all of the module's sections, and perform work for each section we recognize. To make it easier to handle the unexpected absence of a section, and to make the section-specific logic easer to read, let's factor the section search into a helper. Similar is already done in the core module loader, and other architectures (and ideally we'd unify these in future). If we expect a module to have an ftrace trampoline section, but it doesn't have one, we'll now reject loading the module. When ARM64_MODULE_PLTS is selected, any correctly built module should have one (and this is assumed by arm64's ftrace PLT code) and the absence of such a section implies something has gone wrong at build time. Subsequent patches will make use of the new helper. Signed-off-by: Mark Rutland Reviewed-by: Ard Biesheuvel Reviewed-by: Torsten Duwe Tested-by: Amit Daniel Kachhap Tested-by: Torsten Duwe Cc: Catalin Marinas Cc: James Morse Cc: Will Deacon Cc: Stephen Boyd Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/module.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -470,22 +470,39 @@ overflow: return -ENOEXEC; } -int module_finalize(const Elf_Ehdr *hdr, - const Elf_Shdr *sechdrs, - struct module *me) +static const Elf_Shdr *find_section(const Elf_Ehdr *hdr, + const Elf_Shdr *sechdrs, + const char *name) { const Elf_Shdr *s, *se; const char *secstrs = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; for (s = sechdrs, se = sechdrs + hdr->e_shnum; s < se; s++) { - if (strcmp(".altinstructions", secstrs + s->sh_name) == 0) - apply_alternatives_module((void *)s->sh_addr, s->sh_size); + if (strcmp(name, secstrs + s->sh_name) == 0) + return s; + } + + return NULL; +} + +int module_finalize(const Elf_Ehdr *hdr, + const Elf_Shdr *sechdrs, + struct module *me) +{ + const Elf_Shdr *s; + + s = find_section(hdr, sechdrs, ".altinstructions"); + if (s) + apply_alternatives_module((void *)s->sh_addr, s->sh_size); + #ifdef CONFIG_ARM64_MODULE_PLTS - if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE) && - !strcmp(".text.ftrace_trampoline", secstrs + s->sh_name)) - me->arch.ftrace_trampoline = (void *)s->sh_addr; -#endif + if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE)) { + s = find_section(hdr, sechdrs, ".text.ftrace_trampoline"); + if (!s) + return -ENOEXEC; + me->arch.ftrace_trampoline = (void *)s->sh_addr; } +#endif return 0; }