From patchwork Wed Aug 29 11:56:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 963412 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 420kgN73Shz9s3C for ; Wed, 29 Aug 2018 21:59:12 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C6A9VrpL"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 420kgN5F5qzF32n for ; Wed, 29 Aug 2018 21:59:12 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C6A9VrpL"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::543; helo=mail-pg1-x543.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C6A9VrpL"; dkim-atps=neutral Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 420kd22jHWzF31M for ; Wed, 29 Aug 2018 21:57:10 +1000 (AEST) Received: by mail-pg1-x543.google.com with SMTP id e2-v6so2223177pgv.5 for ; Wed, 29 Aug 2018 04:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=YSlkv/ennmI6ACgshdnNVqeN3RKbGypFLZjDnsrzG2A=; b=C6A9VrpLTsMm1687yvDbQM4CLV90ctJliiuNcXCMuB+KtYHT1tk4EQYAwXY8jA+fb9 wduY6Bhwmxc5N/rwSMZwLW69uDWQ+uVO+2Bs/0W67EF6PbltlnwEN+7AVyszVW+izJE6 Mwv/FNPGpjKHYQNtExn5h0Dc8X+kp+v9wZRHkKRaGm1OWeK7L2Gi23eU4rOpX3Rz/ENR Z1bi4UhE0AbSA1MNVym4l+o1WisVHq2wVfSdSWaycI3tv5xklBeYujykRLJF7lBeTeL8 Qm1szzNo7hF7C2CeA6JjyuWHXN7y5ZFwUUAdbSG7lv7vOLU3vDwWv/EzYpyRch5KOl8x iTAQ== 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; bh=YSlkv/ennmI6ACgshdnNVqeN3RKbGypFLZjDnsrzG2A=; b=kATlJHuWE7TAqnc+22Ypm9pT9r4j7vX5JN1+5LCNE+nKsJ+2+K1BScaz5y7C2HXQIU b9vYgJ+58ABTi7WMXH3763x+Fv2ceQk94hPnQbvFhql9AQjqj0dU32C/mkJlZjrIz1d/ 2xNGdEmI1DQs8CopbNOEjJ/hbxinfWcOaa6a7szg6oi24HXIi1PpE+aRTeMJ58sI/8Uq gkM5DMxDKX/PfBYVkKrxop0K4Ye940CNMYE5w0tgf7DE3yPlpvmaArFbCr/b3l8xXhig lH6LxdBZnYU/VXAmYBXHHOyZOGFHTIm5iOjW3Kp34gdouAFNiOXUleyxdQRoaDWYx7v2 uAyQ== X-Gm-Message-State: APzg51AJeXzYX79lt2lS+GSxWEJnbHfAUjMHcQNi20iO5BD+W8/HzXks kjp2YET59UcNHu9FUwGQyxNJVigP X-Google-Smtp-Source: ANB0VdZjllikcOlswP0bsWPi+2IJ4hnJszQiuPKqOAcv6/eB3ty5L/qI81d08JaU0nfMoDvsU9Ew7w== X-Received: by 2002:a62:e813:: with SMTP id c19-v6mr5691077pfi.124.1535543828010; Wed, 29 Aug 2018 04:57:08 -0700 (PDT) Received: from roar.au.ibm.com (59-102-81-67.tpgi.com.au. [59.102.81.67]) by smtp.gmail.com with ESMTPSA id d132-v6sm9168888pgc.93.2018.08.29.04.57.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Aug 2018 04:57:07 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [RFC PATCH] powerpc/64/module: REL32 relocation range check Date: Wed, 29 Aug 2018 21:56:56 +1000 Message-Id: <20180829115656.9878-1-npiggin@gmail.com> X-Mailer: git-send-email 2.18.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin , Alan Modra Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The recent module relocation overflow crash demonstrated that we have no range checking on REL32 relative relocations. This patch implements a basic check, the same kernel that previously oopsed and rebooted now continues with some of these errors when loading the module: module_64: x_tables: REL32 527703503449812 out of range! Question is whether other relocations (ADDR32, REL16, TOC16, etc.) should also have overflow checks. --- arch/powerpc/kernel/module_64.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index a2636c250b7b..2a2fb656d23b 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -678,7 +678,14 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, case R_PPC64_REL32: /* 32 bits relative (used by relative exception tables) */ - *(u32 *)location = value - (unsigned long)location; + /* Convert value to relative */ + value -= (unsigned long)location; + if (value + 0x80000000 > 0xffffffff) { + pr_err("%s: REL32 %li out of range!\n", + me->name, (long int)value); + return -ENOEXEC; + } + *(u32 *)location = value; break; case R_PPC64_TOCSAVE: