Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp106493ybg; Mon, 8 Jun 2020 17:46:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtq+0TVmg7+C/ltEj9K9HLXhfoyUtn+BimlOQLT8/5+88UfTgJBFNmM3J1bjHBc3a4fSA9 X-Received: by 2002:aa7:c3d7:: with SMTP id l23mr4229665edr.264.1591663564271; Mon, 08 Jun 2020 17:46:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663564; cv=none; d=google.com; s=arc-20160816; b=j/83eiW+b51ODNfvXAyap60qCs8aYHenzVxIavOftLlDnZ7FjeV5akDXeZK3K6pjv5 HuTsTO/Hs4/Ut14/TiG6R+hWxFbzNWLgoiF8cbXarftWAhGh+HXezRlfHtugAV/l0nxW r66rQfTk4VoF5t6o9A2DsLWYyiyFy8fFrH2mmCpvWrNx9fxP1lKAnF5JU1+Ujarjjok6 /qCLZe6CSqDXCrt4C0kqcWy5cUApg1zcYnd/NbJKb8nmZ4LvBiYqP8DAwpAXQ3JDRH1n lUp+7uf1SoOeSHg/+U/j0UXrxiCZZlDUYTlFP9YBSl0x6htUFunXRpJ9KznMEtRFu3pU u1jw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2Kb9EbOUOPjV1uOWZr1U9DrMp9gTbUYR2ephopnpHgY=; b=y01OOIPLvW1KZMMBPbQwYRBWlAqSNc6yPkFcjyXtW5CiSgmYsKwc+xkMhkXO+Kzo0e DJBFDx4GJBUbYrd3qOk1+EXKn8EoEtLNsRYSElzj5r/tjtN60VWKlVwuXdG+nzv28L+5 AE4WX+fCTJvZgdJx+U+3B+atCnnvpKlcIE0Lmfl8d/2vb0s227YxDcjVFgZhm9vVWZ9U xTsp4kZjeWr5pZCu0XsNWUtOCS3h8tjOxwsHnSO/n2pZzJDni2gBU55iXjhr5WFPqbwg PkBgkQ6TkTPSKeXo05RWeIPmB1VAMVG12tKgwpgExn+tgENlHE5ew2zVZ3wlvhOIHaIz ty9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SvEmzW5f; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b16si9910273edw.278.2020.06.08.17.45.41; Mon, 08 Jun 2020 17:46:04 -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=SvEmzW5f; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728800AbgFIAoD (ORCPT + 99 others); Mon, 8 Jun 2020 20:44:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:59246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729036AbgFHXMD (ORCPT ); Mon, 8 Jun 2020 19:12:03 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 81405214D8; Mon, 8 Jun 2020 23:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657922; bh=FVGe8qaMruNT+7gpi3rEtG8gVXNp1V100Vai5EX7ITI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SvEmzW5f5kwcespfbLpVWQiP9BnN0d+t2Hj4sDcwBH8OopnPsdH+gvs8kQ6KwxEqC SNlY0YPgTjaSeF3vVCHdksgZWdLx3mCWdmi097rNOmxLsGrmMgyxJAFPOuewnUfRqe 6iafYs+cJurz/xJcrBJ/PNOBNAYabZCsEu5SGGDg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ilya Leoshkevich , Daniel Borkmann , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 271/274] s390/bpf: Maintain 8-byte stack alignment Date: Mon, 8 Jun 2020 19:06:04 -0400 Message-Id: <20200608230607.3361041-271-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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