Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756445AbcCBADB (ORCPT ); Tue, 1 Mar 2016 19:03:01 -0500 Received: from mail177-1.suw61.mandrillapp.com ([198.2.177.1]:59827 "EHLO mail177-1.suw61.mandrillapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932612AbcCAX6j (ORCPT ); Tue, 1 Mar 2016 18:58:39 -0500 From: Greg Kroah-Hartman Subject: [PATCH 4.4 320/342] x86/mpx: Fix off-by-one comparison with nr_registers X-Mailer: git-send-email 2.7.2 To: Cc: Greg Kroah-Hartman , , Colin Ian King , Dave Hansen , Borislav Petkov , "Kirill A . Shutemov" , Thomas Gleixner Message-Id: <20160301234538.213995355@linuxfoundation.org> In-Reply-To: <20160301234527.990448862@linuxfoundation.org> References: <20160301234527.990448862@linuxfoundation.org> X-Report-Abuse: Please forward a copy of this message, including all headers, to abuse@mandrill.com X-Report-Abuse: You can also report abuse here: http://mandrillapp.com/contact/abuse?id=30481620.3c35a94be3be4cfc92ac73e2b8805a70 X-Mandrill-User: md_30481620 Date: Tue, 01 Mar 2016 23:55:37 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1359 Lines: 36 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King commit 9bf148cb0812595bfdf5100bd2c07e9bec9c6ef5 upstream. In the unlikely event that regno == nr_registers then we get an array overrun on regoff because the invalid register check is currently off-by-one. Fix this with a check that regno is >= nr_registers instead. Detected with static analysis using CoverityScan. Fixes: fcc7ffd67991 "x86, mpx: Decode MPX instruction to get bound violation information" Signed-off-by: Colin Ian King Acked-by: Dave Hansen Cc: Borislav Petkov Cc: "Kirill A . Shutemov" Link: http://lkml.kernel.org/r/1456512931-3388-1-git-send-email-colin.king@canonical.com Signed-off-by: Thomas Gleixner Signed-off-by: Greg Kroah-Hartman diff --git a/arch/x86/mm/mpx.c b/arch/x86/mm/mpx.c index b2fd67da1701..ef05755a1900 100644 --- a/arch/x86/mm/mpx.c +++ b/arch/x86/mm/mpx.c @@ -123,7 +123,7 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs, break; } - if (regno > nr_registers) { + if (regno >= nr_registers) { WARN_ONCE(1, "decoded an instruction with an invalid register"); return -EINVAL; }