From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36B34C433DF for ; Mon, 18 May 2020 02:21:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B23D207BB for ; Mon, 18 May 2020 02:21:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589768467; bh=7RJuET2p1c9crhC6k5Md3KsYrDZ64Vq388qDBF/PKT4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=AY/i6uRVryO6UDg/6o3A/SpgypulRLYo4+3zoiV80ultZQ5VRptQvGFKoHz9ukceO galUPdIweRiEx6+dtmWozU1THnkEq1l0Sv0UKxW03iUY0uhzqEE7HMWZuaWMTVbQpT eQXIlcaqehELjyrIKUOVhZ0ABn533YHl3Y0T4P/o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726803AbgERCVG (ORCPT ); Sun, 17 May 2020 22:21:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:52582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726680AbgERCVF (ORCPT ); Sun, 17 May 2020 22:21:05 -0400 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9334420758; Mon, 18 May 2020 02:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589768464; bh=7RJuET2p1c9crhC6k5Md3KsYrDZ64Vq388qDBF/PKT4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qKUPHDhKfAvKoQDw6aUbF5oxk/2fSXt6cYTcG445x6tHLCS0hMJXSKIXc5Z28WHUO nlFuCGycnKryukgl1b3dKlivig1RoGMgEXo6P+4drDpHbZO6YsywoMt6lOz6h4/dae CgzG2Fh0kTL1dKHu4p+ITL+Ewb1+xwPHzKxpolUU= Date: Mon, 18 May 2020 11:20:59 +0900 From: Masami Hiramatsu To: Kees Cook Cc: Andrew Jeffery , linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk, mhiramat@kernel.org, labbott@redhat.com, mathieu.desnoyers@efficios.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ARM: kprobes: Avoid fortify_panic() when copying optprobe template Message-Id: <20200518112059.c19899ffb17a4843bf4f74ab@kernel.org> In-Reply-To: <202005171447.00CFE0C@keescook> References: <20200517153959.293224-1-andrew@aj.id.au> <202005171447.00CFE0C@keescook> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 17 May 2020 14:48:52 -0700 Kees Cook wrote: > On Mon, May 18, 2020 at 01:09:59AM +0930, Andrew Jeffery wrote: > > As mentioned, a couple of attempts have been made to address the issue > > by casting a pointer to optprobe_template_entry before providing it to > > memcpy(), however gccs such as Ubuntu 20.04's arm-linux-gnueabi-gcc > > 9.3.0 (Ubuntu 9.3.0-10ubuntu1) see through these efforts. > > Ah, dang. :P > > How about converting them all to unsized arrays, which would also allow > the code to drop the "&" everywhere, I think. This is untested: > This looks good to me since it uses same technique in sections.h. Acked-by: Masami Hiramatsu Thank you! > > diff --git a/arch/arm/include/asm/kprobes.h b/arch/arm/include/asm/kprobes.h > index 213607a1f45c..e26a278d301a 100644 > --- a/arch/arm/include/asm/kprobes.h > +++ b/arch/arm/include/asm/kprobes.h > @@ -44,20 +44,20 @@ int kprobe_exceptions_notify(struct notifier_block *self, > unsigned long val, void *data); > > /* optinsn template addresses */ > -extern __visible kprobe_opcode_t optprobe_template_entry; > -extern __visible kprobe_opcode_t optprobe_template_val; > -extern __visible kprobe_opcode_t optprobe_template_call; > -extern __visible kprobe_opcode_t optprobe_template_end; > -extern __visible kprobe_opcode_t optprobe_template_sub_sp; > -extern __visible kprobe_opcode_t optprobe_template_add_sp; > -extern __visible kprobe_opcode_t optprobe_template_restore_begin; > -extern __visible kprobe_opcode_t optprobe_template_restore_orig_insn; > -extern __visible kprobe_opcode_t optprobe_template_restore_end; > +extern __visible kprobe_opcode_t optprobe_template_entry[]; > +extern __visible kprobe_opcode_t optprobe_template_val[]; > +extern __visible kprobe_opcode_t optprobe_template_call[]; > +extern __visible kprobe_opcode_t optprobe_template_end[]; > +extern __visible kprobe_opcode_t optprobe_template_sub_sp[]; > +extern __visible kprobe_opcode_t optprobe_template_add_sp[]; > +extern __visible kprobe_opcode_t optprobe_template_restore_begin[]; > +extern __visible kprobe_opcode_t optprobe_template_restore_orig_insn[]; > +extern __visible kprobe_opcode_t optprobe_template_restore_end[]; > > #define MAX_OPTIMIZED_LENGTH 4 > #define MAX_OPTINSN_SIZE \ > - ((unsigned long)&optprobe_template_end - \ > - (unsigned long)&optprobe_template_entry) > + ((unsigned long)optprobe_template_end - \ > + (unsigned long)optprobe_template_entry) > #define RELATIVEJUMP_SIZE 4 > > struct arch_optimized_insn { > diff --git a/arch/arm/probes/kprobes/opt-arm.c b/arch/arm/probes/kprobes/opt-arm.c > index 7a449df0b359..c78180172120 100644 > --- a/arch/arm/probes/kprobes/opt-arm.c > +++ b/arch/arm/probes/kprobes/opt-arm.c > @@ -85,21 +85,21 @@ asm ( > "optprobe_template_end:\n"); > > #define TMPL_VAL_IDX \ > - ((unsigned long *)&optprobe_template_val - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_val - (unsigned long *)optprobe_template_entry) > #define TMPL_CALL_IDX \ > - ((unsigned long *)&optprobe_template_call - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_call - (unsigned long *)optprobe_template_entry) > #define TMPL_END_IDX \ > - ((unsigned long *)&optprobe_template_end - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_end - (unsigned long *)optprobe_template_entry) > #define TMPL_ADD_SP \ > - ((unsigned long *)&optprobe_template_add_sp - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_add_sp - (unsigned long *)optprobe_template_entry) > #define TMPL_SUB_SP \ > - ((unsigned long *)&optprobe_template_sub_sp - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_sub_sp - (unsigned long *)optprobe_template_entry) > #define TMPL_RESTORE_BEGIN \ > - ((unsigned long *)&optprobe_template_restore_begin - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_restore_begin - (unsigned long *)optprobe_template_entry) > #define TMPL_RESTORE_ORIGN_INSN \ > - ((unsigned long *)&optprobe_template_restore_orig_insn - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_restore_orig_insn - (unsigned long *)optprobe_template_entry) > #define TMPL_RESTORE_END \ > - ((unsigned long *)&optprobe_template_restore_end - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_restore_end - (unsigned long *)optprobe_template_entry) > > /* > * ARM can always optimize an instruction when using ARM ISA, except > @@ -234,7 +234,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, struct kprobe *or > } > > /* Copy arch-dep-instance from template. */ > - memcpy(code, (unsigned long *)&optprobe_template_entry, > + memcpy(code, (unsigned long *)optprobe_template_entry, > TMPL_END_IDX * sizeof(kprobe_opcode_t)); > > /* Adjust buffer according to instruction. */ > > -- > Kees Cook -- Masami Hiramatsu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A49A0C433E0 for ; Mon, 18 May 2020 02:21:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E8EB207BB for ; Mon, 18 May 2020 02:21:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qYBzwG8r"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="qKUPHDhK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E8EB207BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Mime-Version:References:In-Reply-To: Message-Id:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=S18A2MoGnJJ6uOqHEDoFtzeqmvfSriBRCeeOf/l6B2g=; b=qYBzwG8rxDCiLQ LKoBcbn/ckhMHTEt3k/ohuX1UeBd1B80xFk6H5znZ6ohsQKZ87B1hFVh+WtuiHgqen91/dDPMnicH GKDWWBUCQKDEamATkd37t6SOfLBuFA+yWk+Cnr3qEhVM7PiJ7GE7mVEHMPyJEbdQ3hjgiZZFkxPnC yyM4bNYT9rNaYFFCQ/YkiBmJ3CB/907a0YaS0iCr6omANHShr1jKFzF71n/zbmZ6l/90CsCDBY6CC zKynZl0zdegNnp/gbNP5ATndkOJ7nWDlUAH+yegJKIgvXLiGxWhhgvLzz2kZpuj2TH5xMQd8/bY8z nDyQpk61ldFZ6Qwil8dw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jaVOx-0007Ww-29; Mon, 18 May 2020 02:21:11 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jaVOt-0007Vu-Ky for linux-arm-kernel@lists.infradead.org; Mon, 18 May 2020 02:21:09 +0000 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9334420758; Mon, 18 May 2020 02:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589768464; bh=7RJuET2p1c9crhC6k5Md3KsYrDZ64Vq388qDBF/PKT4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qKUPHDhKfAvKoQDw6aUbF5oxk/2fSXt6cYTcG445x6tHLCS0hMJXSKIXc5Z28WHUO nlFuCGycnKryukgl1b3dKlivig1RoGMgEXo6P+4drDpHbZO6YsywoMt6lOz6h4/dae CgzG2Fh0kTL1dKHu4p+ITL+Ewb1+xwPHzKxpolUU= Date: Mon, 18 May 2020 11:20:59 +0900 From: Masami Hiramatsu To: Kees Cook Subject: Re: [PATCH] ARM: kprobes: Avoid fortify_panic() when copying optprobe template Message-Id: <20200518112059.c19899ffb17a4843bf4f74ab@kernel.org> In-Reply-To: <202005171447.00CFE0C@keescook> References: <20200517153959.293224-1-andrew@aj.id.au> <202005171447.00CFE0C@keescook> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200517_192107_729956_387E301C X-CRM114-Status: GOOD ( 16.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , linux@armlinux.org.uk, linux-kernel@vger.kernel.org, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, labbott@redhat.com, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun, 17 May 2020 14:48:52 -0700 Kees Cook wrote: > On Mon, May 18, 2020 at 01:09:59AM +0930, Andrew Jeffery wrote: > > As mentioned, a couple of attempts have been made to address the issue > > by casting a pointer to optprobe_template_entry before providing it to > > memcpy(), however gccs such as Ubuntu 20.04's arm-linux-gnueabi-gcc > > 9.3.0 (Ubuntu 9.3.0-10ubuntu1) see through these efforts. > > Ah, dang. :P > > How about converting them all to unsized arrays, which would also allow > the code to drop the "&" everywhere, I think. This is untested: > This looks good to me since it uses same technique in sections.h. Acked-by: Masami Hiramatsu Thank you! > > diff --git a/arch/arm/include/asm/kprobes.h b/arch/arm/include/asm/kprobes.h > index 213607a1f45c..e26a278d301a 100644 > --- a/arch/arm/include/asm/kprobes.h > +++ b/arch/arm/include/asm/kprobes.h > @@ -44,20 +44,20 @@ int kprobe_exceptions_notify(struct notifier_block *self, > unsigned long val, void *data); > > /* optinsn template addresses */ > -extern __visible kprobe_opcode_t optprobe_template_entry; > -extern __visible kprobe_opcode_t optprobe_template_val; > -extern __visible kprobe_opcode_t optprobe_template_call; > -extern __visible kprobe_opcode_t optprobe_template_end; > -extern __visible kprobe_opcode_t optprobe_template_sub_sp; > -extern __visible kprobe_opcode_t optprobe_template_add_sp; > -extern __visible kprobe_opcode_t optprobe_template_restore_begin; > -extern __visible kprobe_opcode_t optprobe_template_restore_orig_insn; > -extern __visible kprobe_opcode_t optprobe_template_restore_end; > +extern __visible kprobe_opcode_t optprobe_template_entry[]; > +extern __visible kprobe_opcode_t optprobe_template_val[]; > +extern __visible kprobe_opcode_t optprobe_template_call[]; > +extern __visible kprobe_opcode_t optprobe_template_end[]; > +extern __visible kprobe_opcode_t optprobe_template_sub_sp[]; > +extern __visible kprobe_opcode_t optprobe_template_add_sp[]; > +extern __visible kprobe_opcode_t optprobe_template_restore_begin[]; > +extern __visible kprobe_opcode_t optprobe_template_restore_orig_insn[]; > +extern __visible kprobe_opcode_t optprobe_template_restore_end[]; > > #define MAX_OPTIMIZED_LENGTH 4 > #define MAX_OPTINSN_SIZE \ > - ((unsigned long)&optprobe_template_end - \ > - (unsigned long)&optprobe_template_entry) > + ((unsigned long)optprobe_template_end - \ > + (unsigned long)optprobe_template_entry) > #define RELATIVEJUMP_SIZE 4 > > struct arch_optimized_insn { > diff --git a/arch/arm/probes/kprobes/opt-arm.c b/arch/arm/probes/kprobes/opt-arm.c > index 7a449df0b359..c78180172120 100644 > --- a/arch/arm/probes/kprobes/opt-arm.c > +++ b/arch/arm/probes/kprobes/opt-arm.c > @@ -85,21 +85,21 @@ asm ( > "optprobe_template_end:\n"); > > #define TMPL_VAL_IDX \ > - ((unsigned long *)&optprobe_template_val - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_val - (unsigned long *)optprobe_template_entry) > #define TMPL_CALL_IDX \ > - ((unsigned long *)&optprobe_template_call - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_call - (unsigned long *)optprobe_template_entry) > #define TMPL_END_IDX \ > - ((unsigned long *)&optprobe_template_end - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_end - (unsigned long *)optprobe_template_entry) > #define TMPL_ADD_SP \ > - ((unsigned long *)&optprobe_template_add_sp - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_add_sp - (unsigned long *)optprobe_template_entry) > #define TMPL_SUB_SP \ > - ((unsigned long *)&optprobe_template_sub_sp - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_sub_sp - (unsigned long *)optprobe_template_entry) > #define TMPL_RESTORE_BEGIN \ > - ((unsigned long *)&optprobe_template_restore_begin - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_restore_begin - (unsigned long *)optprobe_template_entry) > #define TMPL_RESTORE_ORIGN_INSN \ > - ((unsigned long *)&optprobe_template_restore_orig_insn - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_restore_orig_insn - (unsigned long *)optprobe_template_entry) > #define TMPL_RESTORE_END \ > - ((unsigned long *)&optprobe_template_restore_end - (unsigned long *)&optprobe_template_entry) > + ((unsigned long *)optprobe_template_restore_end - (unsigned long *)optprobe_template_entry) > > /* > * ARM can always optimize an instruction when using ARM ISA, except > @@ -234,7 +234,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op, struct kprobe *or > } > > /* Copy arch-dep-instance from template. */ > - memcpy(code, (unsigned long *)&optprobe_template_entry, > + memcpy(code, (unsigned long *)optprobe_template_entry, > TMPL_END_IDX * sizeof(kprobe_opcode_t)); > > /* Adjust buffer according to instruction. */ > > -- > Kees Cook -- Masami Hiramatsu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel