Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1973248ima; Thu, 25 Oct 2018 07:47:20 -0700 (PDT) X-Google-Smtp-Source: AJdET5dySI29L+2o7127KHeucf2lHVyGgZsUAJQlkPXXStmihFj0W0hdRWTdCVjYurBAHmOHHyeV X-Received: by 2002:a63:184a:: with SMTP id 10-v6mr1725403pgy.81.1540478840929; Thu, 25 Oct 2018 07:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540478840; cv=none; d=google.com; s=arc-20160816; b=P+lQi7U9I0/NXFEiew5Xx1mZLJRIAWqpiNwFUapMqDTVoLOk5lMf/Zqzg/yzrxyOBE V06ZfzpjURGDfEiSvq1lDJYXiOj4dMzyqWYr35nSH4g6INIi2aWYIuDhdCXenGm+ueqy MnALrHlgco1wpT8SKIwgE1leXIaBFNKQSsNG9AmoVSQz7Oj4SDenNjRgr5mow/MmAQtz nyA5V20eeDE3A9c4RyaKaTnBj2NmVN6P77Gyp/BVf5iMlVd8o1CU1Y2P4I/o17G806p8 FPLmy3ZMFQowKLGSNvNcWKIDg4BiHO8H4Qrl307StL08xGpnoQs2u6SMILJSidxjQC1/ ZZrA== 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=C8bStTLvhSeQjx4nftFTBcNJW6useSIWwX07GqCEIiQ=; b=XgBhSALaLCxm/S5QGsrkuVTZEV8q/n5zDmWg7td8U2Tj3JJsMwmD4V4nlI+sZSU98N wYWIlaOWSwm8XjB4Q1FtMpGrz3n/GU5filPgNauXjKb1Lso7jbXF7wA2fYUaSLcOievx 2ZjlBnA2vpVojSfuw/76H9bQxY1IvArr+/yf235eocEG+RTIs0YWm+MLROVxybefXUHp vzPBC8zi+VjkjkpY3GfkkxobNz6dwSRipIPgHzgHbyodEEolMdI1ccb176GjVTOKFc7i zfABDFOUi4jz0FgHqfKgOiZg++cOIllZRkB3fh3x7XnjLK3K01f0Bd8HWXXzRvuqfrzj 2bEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="p+/Rwl6c"; 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 m6-v6si8423103pfg.282.2018.10.25.07.47.04; Thu, 25 Oct 2018 07:47:20 -0700 (PDT) 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="p+/Rwl6c"; 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 S1728534AbeJYWrb (ORCPT + 99 others); Thu, 25 Oct 2018 18:47:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:55532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727433AbeJYWra (ORCPT ); Thu, 25 Oct 2018 18:47:30 -0400 Received: from sasha-vm.mshome.net (unknown [167.98.65.38]) (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 752E52085A; Thu, 25 Oct 2018 14:14:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1540476874; bh=r3qMu/c6UMYlBb8stk9qiIBL7pfn9hhAWXa+NM3Ymzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p+/Rwl6ccFzjFGa3+ITo7QsjgqpwDi08oUvpqCwvEprpeIILKdea5Mrvod/VXbSO9 6cypcNw175B0gY2g/E8WOCSFg8mwtqHuzh5GvwbTKFQrwDRfL7SAMreBEGxridgz2V IQmLANcDyEQY4KYbN5e9kCMo5DFx/ziHXeQ87Byo= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matt Redfearn , Marcin Nowakowski , James Hogan , Ingo Molnar , Paul Burton , linux-mips@linux-mips.org, Ralf Baechle , Sasha Levin Subject: [PATCH AUTOSEL 4.9 04/98] MIPS: Handle non word sized instructions when examining frame Date: Thu, 25 Oct 2018 10:12:49 -0400 Message-Id: <20181025141423.213774-4-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025141423.213774-1-sashal@kernel.org> References: <20181025141423.213774-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matt Redfearn [ Upstream commit 11887ed172a6960673f130dad8f8fb42778f64d7 ] Commit 34c2f668d0f6b ("MIPS: microMIPS: Add unaligned access support.") added fairly broken support for handling 16bit microMIPS instructions in get_frame_info(). It adjusts the instruction pointer by 16bits in the case of a 16bit sp move instruction, but not any other 16bit instruction. Commit b6c7a324df37 ("MIPS: Fix get_frame_info() handling of microMIPS function size") goes some way to fixing get_frame_info() to iterate over microMIPS instuctions, but the instruction pointer is still manipulated using a postincrement, and is of union mips_instruction type. Since the union is sized to the largest member (a word), but microMIPS instructions are a mix of halfword and word sizes, the function does not always iterate correctly, ending up misaligned with the instruction stream and interpreting it incorrectly. Since the instruction modifying the stack pointer is usually the first in the function, that one is usually handled correctly. But the instruction which saves the return address to the sp is some variable number of instructions into the frame and is frequently missed due to not being on a word boundary, leading to incomplete walking of the stack. Fix this by incrementing the instruction pointer based on the size of the previously decoded instruction (& remove the hack introduced by commit 34c2f668d0f6b ("MIPS: microMIPS: Add unaligned access support.") which adjusts the instruction pointer in the case of a 16bit sp move instruction, but not any other). Fixes: 34c2f668d0f6b ("MIPS: microMIPS: Add unaligned access support.") Signed-off-by: Matt Redfearn Cc: Marcin Nowakowski Cc: James Hogan Cc: Ingo Molnar Cc: Paul Burton Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/16953/ Signed-off-by: Ralf Baechle Signed-off-by: Sasha Levin --- arch/mips/kernel/process.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index 0211dc737a21..1cc133e7026f 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -346,6 +346,7 @@ static int get_frame_info(struct mips_frame_info *info) bool is_mmips = IS_ENABLED(CONFIG_CPU_MICROMIPS); union mips_instruction insn, *ip, *ip_end; const unsigned int max_insns = 128; + unsigned int last_insn_size = 0; unsigned int i; info->pc_offset = -1; @@ -357,15 +358,19 @@ static int get_frame_info(struct mips_frame_info *info) ip_end = (void *)ip + info->func_size; - for (i = 0; i < max_insns && ip < ip_end; i++, ip++) { + for (i = 0; i < max_insns && ip < ip_end; i++) { + ip = (void *)ip + last_insn_size; if (is_mmips && mm_insn_16bit(ip->halfword[0])) { insn.halfword[0] = 0; insn.halfword[1] = ip->halfword[0]; + last_insn_size = 2; } else if (is_mmips) { insn.halfword[0] = ip->halfword[1]; insn.halfword[1] = ip->halfword[0]; + last_insn_size = 4; } else { insn.word = ip->word; + last_insn_size = 4; } if (is_jump_ins(&insn)) @@ -387,8 +392,6 @@ static int get_frame_info(struct mips_frame_info *info) tmp = (ip->halfword[0] >> 1); info->frame_size = -(signed short)(tmp & 0xf); } - ip = (void *) &ip->halfword[1]; - ip--; } else #endif info->frame_size = - ip->i_format.simmediate; -- 2.17.1