Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1594270imd; Sun, 4 Nov 2018 06:01:46 -0800 (PST) X-Google-Smtp-Source: AJdET5dSPytT4fYie3d9lzT4gbKtetgc3oqme6/R0D5x5GWA64oKIXz0GUDYyvZMF6jufHrPif6Y X-Received: by 2002:a63:6bc1:: with SMTP id g184mr17441649pgc.25.1541340106558; Sun, 04 Nov 2018 06:01:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541340106; cv=none; d=google.com; s=arc-20160816; b=ogiyiYrSMwzokOW3GDNmW3xd2FDARgAk4coS1vaQmwwAOVk7UFH50vCSHoiV9y+9nx WhR9ESOLUXSoHRyexfQChhHPNWdOW9tprgPWEx7fOJQapEohZVf/KTZZmJbLMb3DI0xO KhmvMaRqdRf5dnaUueT8W0oU78Mca9va6VO2SBUdcZ7VZFnT+ei8i9zz4T6ifygk2xgu IRfUH/uC3m2zUr/7NvTj2eZ5MGubiOc+MdMTBVzfGzd695xDi+JpVwymlLxfNdpTw8n9 zaMkmx4+/IObfzWCFt4ccg2FUqyipIOhWbF9w9yPQ4raMT2h9cJXNLj8apVTWTKxKA4w 3tuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=0beS1dc7Q1RSw3smmgbhRVfWbIRf7oOaHTqb/sK+rAM=; b=nId7EXaISZFMu58PfFUavivVEBpoxOPditR0h6SD6XC0wf2woWP5z9AVRZbLwyLYjB QfeQOZQZto5r+3QxPDE0qRqJ1QIV6h10hp2KG7R88tcuubZcAOJUzl8DIJIvHRdVOazK xFbI7t70praeTbg/8t8ksMBBnUSTyaobLEoc4pP5GBy8jj8e1Olg5pjz9G/78K5ptQB7 nnrgIRT7dC2rXYnuzUZTEcek1ofVB3w3MBp/Y92YoTLXFV2WpCC4q0ftejGAl6/5ntge g85F0QRn9/5Wtru5IvobMuARWZdi4oRM5EgNWNv4Q33sdxcL0EU+S0HvOu1FMFM8EqCO WlsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2FGiXKmS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb4-v6si39398766plb.170.2018.11.04.06.01.32; Sun, 04 Nov 2018 06:01:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2FGiXKmS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1731226AbeKDXIj (ORCPT + 99 others); Sun, 4 Nov 2018 18:08:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:47494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731192AbeKDXIh (ORCPT ); Sun, 4 Nov 2018 18:08:37 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C9FD020869; Sun, 4 Nov 2018 13:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541339613; bh=9u+KewjeAQMDyqLOeMJLYOrE6sY7eecZ21LFTOBiRm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2FGiXKmSD2OxrdfsN95TmC4Zb9OYyu32tXEWAsi+fmKL2R3jtbuhB1rVldI3k4p5X SbYA2mqze1TKjh3ad1Th0FOYJBR9NWqO81TuNxJmE8iwX0/9/m6wPeEzqQ6CKfCz9D VUZUl3v++jk5GZb1OryJRi4E2Y6+DHiYB7YGLjD4= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Nicholas Piggin , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL 4.14 06/30] powerpc/64/module: REL32 relocation range check Date: Sun, 4 Nov 2018 08:53:01 -0500 Message-Id: <20181104135325.88524-6-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181104135325.88524-1-sashal@kernel.org> References: <20181104135325.88524-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Piggin [ Upstream commit b851ba02a6f3075f0f99c60c4bc30a4af80cf428 ] 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! Possibly other relocations (ADDR32, REL16, TOC16, etc.) should also have overflow checks. Signed-off-by: Nicholas Piggin Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- 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 2a1b1273a312..4d8f6291b766 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -656,7 +656,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: -- 2.17.1