From patchwork Tue Sep 8 15:23:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 264194 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 709BBC433E2 for ; Tue, 8 Sep 2020 19:13:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3579620C09 for ; Tue, 8 Sep 2020 19:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599592420; bh=hsRI/DQtIhUQiWlHw6qbEK4v7Tt/BNhJxhJm/I7Jm4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=WlBwXm+9Wkud7Hm9jNfPeAMMUt0KyKK6UoEFD/ItbVxE3C6bihho+b6i1H89jgJJT oZQ9AL0zZVlzNo3jo6KzAO6zcaKwZsnlvvH8GYnyEKZW2PdyxVTlZOWFZCWVC9XOeu flFhwYvKvrabT204iHRRbM7AdIqnnxpPaKlSfjis= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731760AbgIHTNe (ORCPT ); Tue, 8 Sep 2020 15:13:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:51454 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731202AbgIHQEx (ORCPT ); Tue, 8 Sep 2020 12:04:53 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 AE11B23BEE; Tue, 8 Sep 2020 15:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599579396; bh=hsRI/DQtIhUQiWlHw6qbEK4v7Tt/BNhJxhJm/I7Jm4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qztjcuWZnGZP+OMsOe2shrXYbR9+4/+/AG6sLZtDU/5f6BFPkYQMCqetI6CMGEiXY RWnf+JFZuV/dwy8z42QjsAs/NBvx8duQyp3WSu9ci9QUx3L+sNgqq8igak++u81Cg0 HsmQiFAH6H3CxPcFu99/H37oXnlCuaQ1vLih+ogM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yonghong Song , Alexei Starovoitov , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.8 061/186] bpf: Fix a buffer out-of-bound access when filling raw_tp link_info Date: Tue, 8 Sep 2020 17:23:23 +0200 Message-Id: <20200908152244.620746578@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908152241.646390211@linuxfoundation.org> References: <20200908152241.646390211@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Yonghong Song [ Upstream commit b474959d5afda6e341a02c85f9595d85d39189ae ] Commit f2e10bff16a0 ("bpf: Add support for BPF_OBJ_GET_INFO_BY_FD for bpf_link") added link query for raw_tp. One of fields in link_info is to fill a user buffer with tp_name. The Scurrent checking only declares "ulen && !ubuf" as invalid. So "!ulen && ubuf" will be valid. Later on, we do "copy_to_user(ubuf, tp_name, ulen - 1)" which may overwrite user memory incorrectly. This patch fixed the problem by disallowing "!ulen && ubuf" case as well. Fixes: f2e10bff16a0 ("bpf: Add support for BPF_OBJ_GET_INFO_BY_FD for bpf_link") Signed-off-by: Yonghong Song Signed-off-by: Alexei Starovoitov Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20200821191054.714731-1-yhs@fb.com Signed-off-by: Sasha Levin --- kernel/bpf/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 0fd80ac81f705..72e943b3bd656 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2629,7 +2629,7 @@ static int bpf_raw_tp_link_fill_link_info(const struct bpf_link *link, u32 ulen = info->raw_tracepoint.tp_name_len; size_t tp_len = strlen(tp_name); - if (ulen && !ubuf) + if (!ulen ^ !ubuf) return -EINVAL; info->raw_tracepoint.tp_name_len = tp_len + 1;