Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp838140ybi; Fri, 12 Jul 2019 05:29:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjfiG6u4+/OuOtk7XCUnHPHyPS3NuoPCCjDS7jYtBRIWvbB7RJPOSBFmo0DdGKxrHBtxKz X-Received: by 2002:a17:902:1e9:: with SMTP id b96mr11269794plb.277.1562934582999; Fri, 12 Jul 2019 05:29:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934582; cv=none; d=google.com; s=arc-20160816; b=W/WqYZgBGu6c2am9J7o1k9FoQNoNYMI/yac5/LruuWMQtn4Ayg87qkNM4f5VWAjysG pWeApiCnYTbDEuu4pr+nhefmB7l7gTFoWBF+ENvKWCMOi7igIHyYIkLX1ekCeGxvuKjR /0jNEx2BpoSArIeRsOO5aeZunSHUG9w2ALEdt31YlCMdjeBw9hvK7dP4SKXtUnOR1zde 5S8S1OTACwTVy3RdUKgcS6F1KngyPi87QFASFGlCNUl3WNDatEr+g5p1ZyyZj7+M08Ye /Dibspa0dxXALAjbYtbBlmjZNDDDUoaOw+GUem19AKZyMBlWyyd89gBUc5IzCKY1Ft7/ pjpw== 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=5H0m5SWe1fJurXBzI3pY1m4zynAeFszAgv3eIUWaJ7s=; b=rVT24QeKkN4CVDlG3cXslW0AmR8HjiwzCEqh1CuODKNahD6rj8SBabjp2AOUyYjdUE YeblsaJdAbsobjjl2F/iCuE8eGJpg0CLahzC9rRRM70gEIt52nDwIhGmMwtYTSyu4S54 /KE6pjdr6rQmc0nt9A/zuUvo3fMs5sQeddEA4ke/eiOX4z7PD5+ZM414Mn8qPs5PVaE4 ooyw3xQ/qe6zY0vzFqu1pldWQiovSdjmDFjpEpLLjV4cEpDKqnmXg/0R98jexfOqtYax o2FwYbRs/eAS6mhJOndxnzwPtMQwg3ZbzNR1yzjTzAHz5iVI2Edpq0fQlX/WnfyTdLwD ZcqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YknI4Je5; 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 w18si7570452pjn.74.2019.07.12.05.29.27; Fri, 12 Jul 2019 05:29:42 -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=YknI4Je5; 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 S1728588AbfGLM1T (ORCPT + 99 others); Fri, 12 Jul 2019 08:27:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:39464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728557AbfGLM1P (ORCPT ); Fri, 12 Jul 2019 08:27:15 -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 5D26E216C4; Fri, 12 Jul 2019 12:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934434; bh=b44Im4yuvraejeHtjxj2xoFfQZtu0cWcfXBhkj1k270=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YknI4Je5Yq6u9CfzCSKu1kWbB1uMe1Vm2THJ4bAkw9MCKHd2z3qgCInBIsFFSeqIO oid+pRnxI3qrwwDC2UZv3JfaeP1lWYTBY6yDkd4p7oG9ajuNMRL3dAznb69YTk1sPY RqK0z+kyuoDs2+KHvpuSWpwZN1HaMljpKjZD/NNo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Naveen N. Rao" , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.1 054/138] bpf: fix div64 overflow tests to properly detect errors Date: Fri, 12 Jul 2019 14:18:38 +0200 Message-Id: <20190712121630.742274478@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@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 3e0682695199bad51dd898fe064d1564637ff77a ] If the result of the division is LLONG_MIN, current tests do not detect the error since the return value is truncated to a 32-bit value and ends up being 0. Signed-off-by: Naveen N. Rao Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- .../testing/selftests/bpf/verifier/div_overflow.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/verifier/div_overflow.c b/tools/testing/selftests/bpf/verifier/div_overflow.c index bd3f38dbe796..acab4f00819f 100644 --- a/tools/testing/selftests/bpf/verifier/div_overflow.c +++ b/tools/testing/selftests/bpf/verifier/div_overflow.c @@ -29,8 +29,11 @@ "DIV64 overflow, check 1", .insns = { BPF_MOV64_IMM(BPF_REG_1, -1), - BPF_LD_IMM64(BPF_REG_0, LLONG_MIN), - BPF_ALU64_REG(BPF_DIV, BPF_REG_0, BPF_REG_1), + BPF_LD_IMM64(BPF_REG_2, LLONG_MIN), + BPF_ALU64_REG(BPF_DIV, BPF_REG_2, BPF_REG_1), + BPF_MOV32_IMM(BPF_REG_0, 0), + BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 1), + BPF_MOV32_IMM(BPF_REG_0, 1), BPF_EXIT_INSN(), }, .prog_type = BPF_PROG_TYPE_SCHED_CLS, @@ -40,8 +43,11 @@ { "DIV64 overflow, check 2", .insns = { - BPF_LD_IMM64(BPF_REG_0, LLONG_MIN), - BPF_ALU64_IMM(BPF_DIV, BPF_REG_0, -1), + BPF_LD_IMM64(BPF_REG_1, LLONG_MIN), + BPF_ALU64_IMM(BPF_DIV, BPF_REG_1, -1), + BPF_MOV32_IMM(BPF_REG_0, 0), + BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_1, 1), + BPF_MOV32_IMM(BPF_REG_0, 1), BPF_EXIT_INSN(), }, .prog_type = BPF_PROG_TYPE_SCHED_CLS, -- 2.20.1