From patchwork Tue Mar 6 17:15:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10262279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CB7FE60211 for ; Tue, 6 Mar 2018 17:16:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9EE729101 for ; Tue, 6 Mar 2018 17:16:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE80F29106; Tue, 6 Mar 2018 17:16:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2151129101 for ; Tue, 6 Mar 2018 17:16:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=rL7KB75GMPr6KmSrHUeloMSjA84eII6drnfDGQKmf5s=; b=TUrc3PfIORo2msZyLAKuzSyJ06 CCx+ZGYugRq1YiJX8Sj2XsO/4T9cRURZJNH76v+E83Ok88pHPjygduHdmt2m8OHLGWZfNNDf3ddvk mifTUPPcyXbhIl2wOw086velnvGiTkUtlVIvHAAAbpNZXi7p0IR9xyla8e0Kn8T0ekPaInHt2/Hxp 46g7HrvvwvO+NpeGcQVD8yKrMUyrY2mH03fxe/I+k7YfIydrwV1NeJG8eat8hSEqAYPtSQAN0TzxL 4zoLp44WWim9oxxiyjSNO0ClgnfeFkNP0DRi9NZVwG/XZjBrZwmBTLnHKPnMMgspmmM4KjxOCvEE/ Y5ANa1gg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1etGCD-0003gE-EV; Tue, 06 Mar 2018 17:16:13 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1etGC9-0003dm-W2 for linux-arm-kernel@lists.infradead.org; Tue, 06 Mar 2018 17:16:11 +0000 Received: by mail-wr0-x243.google.com with SMTP id v65so21713788wrc.11 for ; Tue, 06 Mar 2018 09:15:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZIWe4JevUx1yWY0FuHNC6QiwYCK+G7aJ4unHZmLk1Fg=; b=JDe+WnTW79fVd3yGtByd/qdyoblfz1XFOSCvt6kViTYfo6bsqtjUyCnWT0qeX8eSFg 2BxSId80GP7TmZNPR51hlrHE8dolh13TI39S/P/XA3QdqJ5v/KGRvfcTTZVVN1Y0iUxS qTX17J48ktmmg2FI14CEIc0seFDyGxRBkbsE4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZIWe4JevUx1yWY0FuHNC6QiwYCK+G7aJ4unHZmLk1Fg=; b=hXQSOwjhYA0Wdd0nd3CBnLHmn82z3JOoTH/tN/T5P85qaauTqN7kngcRbAL2UxsDSi 45j7DqhRER0KvKIvaTOqln6W/SqZjXWNRh5K05bjUH7YbYhRN9JhG6ScPIaUsHDROiUP 4XOjp/L1ER3v5A7/0Jab6db9h30I4pB90poErcH/umQYbdFMegnBGekWnbPa+YQiEw2c nlWGPlU4DIYi8d9aa3TfIcHw+ufAeLFBo5CerrSjFIy6S1ZI6GndbIGOvYY1FS5KuPRA oPO+Gefny+X/u5aww72+a2PSLJG1suBNiIXND/x9xJE2aVaSWivnZz7HSo5YsqEvk7sE 6x/w== X-Gm-Message-State: APf1xPDI8F/xovTSIfn+u3c4r6pJKzgsU1WOOCCDUgyqcTPnId8Ol72O t2aLnXLmh3k3mgNSNwWyqqaw80BqLtw= X-Google-Smtp-Source: AG47ELtIsBeJIPGMVdt3oHh2CZbOAl1rDdhVLzqS82X3d7/8jWyLTNrsZf18CLSYDIeOLF07/TKrXQ== X-Received: by 10.223.168.46 with SMTP id l43mr17906489wrc.118.1520356558032; Tue, 06 Mar 2018 09:15:58 -0800 (PST) Received: from localhost.localdomain ([160.168.113.39]) by smtp.gmail.com with ESMTPSA id j89sm10570026wrj.92.2018.03.06.09.15.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Mar 2018 09:15:57 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 1/5] arm64: module: don't BUG when exceeding preallocated PLT count Date: Tue, 6 Mar 2018 17:15:31 +0000 Message-Id: <20180306171535.25681-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180306171535.25681-1-ard.biesheuvel@linaro.org> References: <20180306171535.25681-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180306_091610_067551_008F5F88 X-CRM114-Status: GOOD ( 14.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, suzuki.poulose@arm.com, marc.zyngier@arm.com, catalin.marinas@arm.com, Ard Biesheuvel , will.deacon@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When PLTs are emitted at relocation time, we really should not exceed the number that we counted when parsing the relocation tables, and so currently, we BUG() on this condition. However, even though this is a clear bug in this particular piece of code, we can easily recover by failing to load the module. So instead, return 0 from module_emit_plt_entry() if this condition occurs, which is not a valid kernel address, and can hence serve as a flag value that makes the relocation routine bail out. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/module-plts.c | 3 ++- arch/arm64/kernel/module.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/module-plts.c b/arch/arm64/kernel/module-plts.c index ea640f92fe5a..6bf07c602bd4 100644 --- a/arch/arm64/kernel/module-plts.c +++ b/arch/arm64/kernel/module-plts.c @@ -36,7 +36,8 @@ u64 module_emit_plt_entry(struct module *mod, void *loc, const Elf64_Rela *rela, return (u64)&plt[i - 1]; pltsec->plt_num_entries++; - BUG_ON(pltsec->plt_num_entries > pltsec->plt_max_entries); + if (WARN_ON(pltsec->plt_num_entries > pltsec->plt_max_entries)) + return 0; return (u64)&plt[i]; } diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index f469e0435903..c8c6c2828b79 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -386,6 +386,8 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) && ovf == -ERANGE) { val = module_emit_plt_entry(me, loc, &rel[i], sym); + if (!val) + return -ENOEXEC; ovf = reloc_insn_imm(RELOC_OP_PREL, loc, val, 2, 26, AARCH64_INSN_IMM_26); }