Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp589232ybt; Fri, 19 Jun 2020 08:49:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzX3SVYx2Ft9FW1aLJCl0tn4cQr8Tp63u0GP3i3nF8PslB/NLklasbwl2MwbKtfOaSOir7X X-Received: by 2002:a05:6402:128f:: with SMTP id w15mr4114344edv.240.1592581794886; Fri, 19 Jun 2020 08:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592581794; cv=none; d=google.com; s=arc-20160816; b=MBfcPgHAGTayvwMcb8gj1bN6sDHHivaMAJRaG+1H2Ida65sksU/2HVFZ/7bL3pf3A6 c3ycV+w6r8eZxuSYSpmaG7p9p3wKP0pdX6LG8/YHzorJDJPIx+S/V8bfS35XaopKKiwz 2fMQup1sP7EjfIok5sXzBCJq0RM05RVktZKBRz7lsc5IJatvFXtl3nX4cFMjEzifx2IE B6bqvmLlEyIj70m0TeLLun3nVkIaClK/RAJ7CwgActPWq0FR+g5m59P37FGAGWK4p6kC GXDN5XrUrrshdCXiwbsgu3lnCPXJKLROnrrUfSaWpZDXq+Sd55uSQVyTlboX1uj8pT6W RM6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2Kb9EbOUOPjV1uOWZr1U9DrMp9gTbUYR2ephopnpHgY=; b=J2+hfK9DRTL31YsA97RKao5L0Ie8nntHJpiXRJh8n4bj9IRsgNxqW4dbj0YvW4Demh tDGWVWay9lyBkrUjtB/Z40/YYTz6QWJyt2z+INLRJSelxFz0RbAZhwEERk0SuNNhpgWm i12qoKG+0p2BvdPdlkcm/5W/+AmJVWHuQNW5zZf4fz2jLjtFbWOJhTgE40nkSNDWK43u j8BzzS/gQfYp3K6TkfgDtsIPHAaq5WP+qxA579NYJSwJStSWgzKzWwnzFw7FwJIqAxxu 7NLYBKH6pF7ypOeSR7ldT8FDM8CsXBtrEH8LejQezj+k4JMgJasIaspHjKhnsBKjHDWe UEGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aXdWTiq0; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si4148606ejc.659.2020.06.19.08.49.31; Fri, 19 Jun 2020 08:49:54 -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=@kernel.org header.s=default header.b=aXdWTiq0; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405219AbgFSPpN (ORCPT + 99 others); Fri, 19 Jun 2020 11:45:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:59214 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393554AbgFSP12 (ORCPT ); Fri, 19 Jun 2020 11:27:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 673CD21927; Fri, 19 Jun 2020 15:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592580447; bh=FVGe8qaMruNT+7gpi3rEtG8gVXNp1V100Vai5EX7ITI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aXdWTiq0dTroZ8g4s8gdsI1dp5dqN5bKFxghwb6e6kDh5fiRlHIPFr9OK4I/Yywim ywEkNXf2icwuSGo95SlAE0sHa/90taflK+nQLFmXr/PoAB9twnJ2f2ph+1qU32tRhX R03Joo3FQ4XgKcnOf9Yc3dutxwj9DsuSuszBV/lk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilya Leoshkevich , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.7 253/376] s390/bpf: Maintain 8-byte stack alignment Date: Fri, 19 Jun 2020 16:32:51 +0200 Message-Id: <20200619141722.301635803@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141710.350494719@linuxfoundation.org> References: <20200619141710.350494719@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilya Leoshkevich [ Upstream commit effe5be17706167ee968fa28afe40dec9c6f71db ] Certain kernel functions (e.g. get_vtimer/set_vtimer) cause kernel panic when the stack is not 8-byte aligned. Currently JITed BPF programs may trigger this by allocating stack frames with non-rounded sizes and then being interrupted. Fix by using rounded fp->aux->stack_depth. Signed-off-by: Ilya Leoshkevich Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20200602174339.2501066-1-iii@linux.ibm.com Signed-off-by: Sasha Levin --- arch/s390/net/bpf_jit_comp.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c index 8d2134136290..0f37a1b635f8 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c @@ -594,7 +594,7 @@ static void bpf_jit_epilogue(struct bpf_jit *jit, u32 stack_depth) * stack space for the large switch statement. */ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, - int i, bool extra_pass) + int i, bool extra_pass, u32 stack_depth) { struct bpf_insn *insn = &fp->insnsi[i]; u32 dst_reg = insn->dst_reg; @@ -1207,7 +1207,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, */ if (jit->seen & SEEN_STACK) - off = STK_OFF_TCCNT + STK_OFF + fp->aux->stack_depth; + off = STK_OFF_TCCNT + STK_OFF + stack_depth; else off = STK_OFF_TCCNT; /* lhi %w0,1 */ @@ -1249,7 +1249,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, /* * Restore registers before calling function */ - save_restore_regs(jit, REGS_RESTORE, fp->aux->stack_depth); + save_restore_regs(jit, REGS_RESTORE, stack_depth); /* * goto *(prog->bpf_func + tail_call_start); @@ -1519,7 +1519,7 @@ static int bpf_set_addr(struct bpf_jit *jit, int i) * Compile eBPF program into s390x code */ static int bpf_jit_prog(struct bpf_jit *jit, struct bpf_prog *fp, - bool extra_pass) + bool extra_pass, u32 stack_depth) { int i, insn_count, lit32_size, lit64_size; @@ -1527,18 +1527,18 @@ static int bpf_jit_prog(struct bpf_jit *jit, struct bpf_prog *fp, jit->lit64 = jit->lit64_start; jit->prg = 0; - bpf_jit_prologue(jit, fp->aux->stack_depth); + bpf_jit_prologue(jit, stack_depth); if (bpf_set_addr(jit, 0) < 0) return -1; for (i = 0; i < fp->len; i += insn_count) { - insn_count = bpf_jit_insn(jit, fp, i, extra_pass); + insn_count = bpf_jit_insn(jit, fp, i, extra_pass, stack_depth); if (insn_count < 0) return -1; /* Next instruction address */ if (bpf_set_addr(jit, i + insn_count) < 0) return -1; } - bpf_jit_epilogue(jit, fp->aux->stack_depth); + bpf_jit_epilogue(jit, stack_depth); lit32_size = jit->lit32 - jit->lit32_start; lit64_size = jit->lit64 - jit->lit64_start; @@ -1569,6 +1569,7 @@ struct s390_jit_data { */ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) { + u32 stack_depth = round_up(fp->aux->stack_depth, 8); struct bpf_prog *tmp, *orig_fp = fp; struct bpf_binary_header *header; struct s390_jit_data *jit_data; @@ -1621,7 +1622,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) * - 3: Calculate program size and addrs arrray */ for (pass = 1; pass <= 3; pass++) { - if (bpf_jit_prog(&jit, fp, extra_pass)) { + if (bpf_jit_prog(&jit, fp, extra_pass, stack_depth)) { fp = orig_fp; goto free_addrs; } @@ -1635,7 +1636,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp) goto free_addrs; } skip_init_ctx: - if (bpf_jit_prog(&jit, fp, extra_pass)) { + if (bpf_jit_prog(&jit, fp, extra_pass, stack_depth)) { bpf_jit_binary_free(header); fp = orig_fp; goto free_addrs; -- 2.25.1