Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9985876ybi; Wed, 24 Jul 2019 13:34:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWj7gyw5tUX2tRDyTIAgKUfwxJflH7EYvyiWNMGV3zcOScxhoJ3NYjYxgvtRZlGz40OXM4 X-Received: by 2002:a63:66c5:: with SMTP id a188mr82707337pgc.127.1564000487252; Wed, 24 Jul 2019 13:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000487; cv=none; d=google.com; s=arc-20160816; b=aSVdy9r/h4xUlWcPUc8+/JooraeMOPSh/IC6FM66RoJrpDiYrzp0SoopYPVwy4eGD6 R5e3OMpuqcyo8zRS3sZCCQrpzMjuVlLy5IMXg1vsNx2SEcIxfvNx8h6ZhoMpgllibksA Cl/qbZSUxV+Iy/F2BVoPAmZdSpaK/ogdyG3iw2MklSy+7RBJlM6D2GU5UQs1te6IGWwO RR/JyD1hjVgpcHUYCYkW5H4Kn9OktTq71Nvr0wyJ4h9LEpT6sKPJIG6JBUDpUZzcoHal SZpYegFN97VbH6N6Oioc525x7VVw49j1q17DwYce7al7kQTCrK2mIs8vk8+5npV2MOGw 6dnw== 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=EQJBDJUZk0/ShMuAAw2uSFaGNghlccrNHsbYvIIxdjc=; b=PpFDPTkehdaH/nlT6CF+Zpesf3ZrZvWYMMGjjwCmDZyvi2Y/xWQELoKJNpCfCg0rdP F7tfTBzCQnZaCPxKSP5PsKHHVOqTditrERHTs0x1d6+qbFme7w0fdxdu+cpqcnCoP82k l5W4xQskcmer/QEfwi0rFSIbqcvbBvKueSdJw+bMfB9n6g6kD3DsSOBtDQEqUI8LvvGg wMlIssKpqxqBHMZhxviy9wp/qByZrwjK8Fp8cK/2zmOt3hKQcLB4fD51Pe9Ox/c1b5vW cer4iDo2+z2LnqDmmaNCf3sCJ15sqzWiR2eeJGRUflA4pOqPvBClLjGvnFV5ueXLpbu2 wPvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MZy3MTtD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v16si15415260pfi.142.2019.07.24.13.34.32; Wed, 24 Jul 2019 13:34:47 -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=MZy3MTtD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388347AbfGXT3V (ORCPT + 99 others); Wed, 24 Jul 2019 15:29:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:48436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728552AbfGXT3S (ORCPT ); Wed, 24 Jul 2019 15:29:18 -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 5BE8120659; Wed, 24 Jul 2019 19:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563996557; bh=9Pt7VSf7Y+EbxOQtUc7WMxkJU/adgdCjXxViKqeXkv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MZy3MTtDu637Br45f34WkUg8bwVkddz6YTiQMXj6YBkgQtMDa5YUzhiXEjsl2ZoJm oUg9UYDqOIXgAxFQFcZvm/ZiknQCYUTe++e4/RN3FJ+2U7NWkwH1Bw8VDbNhQqC0n7 KgERPHPZBDUovhEe+Evl4KfaqYLrXjihNLAU9qII= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.2 121/413] bpf: fix callees pruning callers Date: Wed, 24 Jul 2019 21:16:52 +0200 Message-Id: <20190724191743.873298644@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@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 [ Upstream commit eea1c227b9e9bad295e8ef984004a9acf12bb68c ] The commit 7640ead93924 partially resolved the issue of callees incorrectly pruning the callers. With introduction of bounded loops and jmps_processed heuristic single verifier state may contain multiple branches and calls. It's possible that new verifier state (for future pruning) will be allocated inside callee. Then callee will exit (still within the same verifier state). It will go back to the caller and there R6-R9 registers will be read and will trigger mark_reg_read. But the reg->live for all frames but the top frame is not set to LIVE_NONE. Hence mark_reg_read will fail to propagate liveness into parent and future walking will incorrectly conclude that the states are equivalent because LIVE_READ is not set. In other words the rule for parent/live should be: whenever register parentage chain is set the reg->live should be set to LIVE_NONE. is_state_visited logic already follows this rule for spilled registers. Fixes: 7640ead93924 ("bpf: verifier: make sure callees don't prune with caller differences") Fixes: f4d7e40a5b71 ("bpf: introduce function calls (verification)") Signed-off-by: Alexei Starovoitov Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index a5c369e60343..11528bdaa9dc 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -6456,17 +6456,18 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx) * the state of the call instruction (with WRITTEN set), and r0 comes * from callee with its full parentage chain, anyway. */ - for (j = 0; j <= cur->curframe; j++) - for (i = j < cur->curframe ? BPF_REG_6 : 0; i < BPF_REG_FP; i++) - cur->frame[j]->regs[i].parent = &new->frame[j]->regs[i]; /* clear write marks in current state: the writes we did are not writes * our child did, so they don't screen off its reads from us. * (There are no read marks in current state, because reads always mark * their parent and current state never has children yet. Only * explored_states can get read marks.) */ - for (i = 0; i < BPF_REG_FP; i++) - cur->frame[cur->curframe]->regs[i].live = REG_LIVE_NONE; + for (j = 0; j <= cur->curframe; j++) { + for (i = j < cur->curframe ? BPF_REG_6 : 0; i < BPF_REG_FP; i++) + cur->frame[j]->regs[i].parent = &new->frame[j]->regs[i]; + for (i = 0; i < BPF_REG_FP; i++) + cur->frame[j]->regs[i].live = REG_LIVE_NONE; + } /* all stack frames are accessible from callee, clear them all */ for (j = 0; j <= cur->curframe; j++) { -- 2.20.1