Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4368732pxj; Tue, 8 Jun 2021 12:35:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYo+GNuUPBTrHqpDbe2XsJ1S4Rmv8DTI2Oj8blSL7OjtHLxTgetnX5SiqM0JP0Ayc4nqbr X-Received: by 2002:a17:907:f9b:: with SMTP id kb27mr14953249ejc.44.1623180930252; Tue, 08 Jun 2021 12:35:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623180930; cv=none; d=google.com; s=arc-20160816; b=DTRfQpVHBL3GWZyovlzcMmu0K1l47clkgvXiEvy647S9afkZ3qpfWEOjhaNumHtbMA q5HFiqI8dZ6oLXBwwpxK3tjlo5wJiefJNPRpXN/S26QAMBUcF63EtDNaGyfmwzL9URpt 8QAtUXAJRkZV+VGqgq0ZtV+fbwaCNR8De7DnaR0wzWeGpRNfo4z3Ifi6Gw4Wwwdpa3ij emfzetcIk/8zd/kzRT7bs6ocOBnk/PDNB1fKCQfBxhKi1DlbJbucUERnLVzSlb1K9txG wylLhy0pbdUdmREbeNpg6evTIlqua2/YVoSYgx3KELTGp9SXUTEQV7Uyg7N3fpzhjIKy 5LfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Fd7s3XBtIP9AgNqbJTqN9qtNZWD9hEVBAnM29W7X9Vs=; b=N3S+BdbdkIELNm7W7QwSaygM1THRdOlaeZGzO/CGBMD209+knvLU2TNm16+ODh4ok+ QTwiplUVlEGEMTtqfhr9zvo7AJcDjljs0bknHJKaImSG2EXfwhDg97rdtkjHXYzK/OtR c868WH1jQhw2/Bm68NwbTX2tVX6UAno1iAXBgW3W7+Vj7wv3IYJzkuD7lsRizIE3Phx0 jDR2WhWpBMzrMjMJa73bv2lRaDFS6BFcNMBzC0pWAcD1B+eNo7xh+R1EPwVIFFAXIWhe hF2kpn+auke0B+jgmei+P6XCVEDgKEpuUIsD4TXfagdqeeQXkITTxb72JKeGOPaNdJ5i RawA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QI0yRamo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e1si458157edk.506.2021.06.08.12.35.06; Tue, 08 Jun 2021 12:35:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QI0yRamo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238450AbhFHTcc (ORCPT + 99 others); Tue, 8 Jun 2021 15:32:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:38704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237135AbhFHTQx (ORCPT ); Tue, 8 Jun 2021 15:16:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9BD2D61476; Tue, 8 Jun 2021 18:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623178269; bh=4FxsOxl0IxUm91bhDt+hrgMMQPhGIbt4bIOedGfT3gk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QI0yRamoFrcdq1u3t/sO1CmFAV4QwfVS+LFIpjTK1VFCIlh+1obPi0dzvUeUvymeg GksqvorEYywHLik1LUF0H4/rB8YHfe0bcU/OdNzC6tcalxdAC5dPFNW9QwiYCc5P3J 7h2Fs0jPXeggKepsM+gdhrY8twf+3N/uhc1041fE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe Leroy , "Naveen N. Rao" , Michael Ellerman Subject: [PATCH 5.12 139/161] powerpc/kprobes: Fix validation of prefixed instructions across page boundary Date: Tue, 8 Jun 2021 20:27:49 +0200 Message-Id: <20210608175950.145668740@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175945.476074951@linuxfoundation.org> References: <20210608175945.476074951@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naveen N. Rao commit 82123a3d1d5a306fdf50c968a474cc60fe43a80f upstream. When checking if the probed instruction is the suffix of a prefixed instruction, we access the instruction at the previous word. If the probed instruction is the very first word of a module, we can end up trying to access an invalid page. Fix this by skipping the check for all instructions at the beginning of a page. Prefixed instructions cannot cross a 64-byte boundary and as such, we don't expect to encounter a suffix as the very first word in a page for kernel text. Even if there are prefixed instructions crossing a page boundary (from a module, for instance), the instruction will be illegal, so preventing probing on the suffix of such prefix instructions isn't worthwhile. Fixes: b4657f7650ba ("powerpc/kprobes: Don't allow breakpoints on suffixes") Cc: stable@vger.kernel.org # v5.8+ Reported-by: Christophe Leroy Signed-off-by: Naveen N. Rao Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/0df9a032a05576a2fa8e97d1b769af2ff0eafbd6.1621416666.git.naveen.n.rao@linux.vnet.ibm.com Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/kprobes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -108,7 +108,6 @@ int arch_prepare_kprobe(struct kprobe *p int ret = 0; struct kprobe *prev; struct ppc_inst insn = ppc_inst_read((struct ppc_inst *)p->addr); - struct ppc_inst prefix = ppc_inst_read((struct ppc_inst *)(p->addr - 1)); if ((unsigned long)p->addr & 0x03) { printk("Attempt to register kprobe at an unaligned address\n"); @@ -116,7 +115,8 @@ int arch_prepare_kprobe(struct kprobe *p } else if (IS_MTMSRD(insn) || IS_RFID(insn) || IS_RFI(insn)) { printk("Cannot register a kprobe on rfi/rfid or mtmsr[d]\n"); ret = -EINVAL; - } else if (ppc_inst_prefixed(prefix)) { + } else if ((unsigned long)p->addr & ~PAGE_MASK && + ppc_inst_prefixed(ppc_inst_read((struct ppc_inst *)(p->addr - 1)))) { printk("Cannot register a kprobe on the second word of prefixed instruction\n"); ret = -EINVAL; }