Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1649187pxy; Mon, 2 Aug 2021 07:04:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynOL5NIvm/Prq6Ge8h1rTVLI7Lta91OR+JTYx5zN4SDeVQ6RlFY29ZNYEjjVpbO5gJdGch X-Received: by 2002:a05:6602:58b:: with SMTP id v11mr2494083iox.70.1627913064430; Mon, 02 Aug 2021 07:04:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627913064; cv=none; d=google.com; s=arc-20160816; b=Czs9aLlird/wHgiHUR+9kZYNmC1PaXVPtHa/d/jEg45UCGPJle4YZuRMuK9AbZLoOW 1/mCiCAdLvZS32qimbQNT2qItNT2Mes/pGMMdMYwfRgyfqOGq5oIn91W/gvgN9Dxaj9A El1GpfT06Mfsc3xTmHd6Z6C5ruHq7pmfDWxLYjOmZXuCw5CsZB2b3gk7w10Ek+oRjuB6 W+Y+eyjL268SAF3PyYaza4gOhqqYQjPnQ7mtG4z4LuW2k+7Hb0fqrCm+0vjDmVyKUimY bqxa3l3/QBFpeklxzeGt69NkgBWI4DUBE6SLFBjcDNN6ToX7IVSaa7KRDiTvNP8pyLH6 iXFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xMkiR1oLZdbVcUFctvj2/H6irufNXBAsS7+wmHTdw1g=; b=R0/zvPeJ/hS7vrtZ408VOqKU8u+EfrbxMQq/komhy4Yd4KcsKx1vqMsSamMZDnjrHr tHlKOGFVoc+w5a9RX8Qv4fCCHbI2FfP2m5U8tYXbHW0vE6+QjN94n8vgGqY4kB+wEWVa xzciM7TCztu2X3nOpKmKywzWZ0VT44ezVSJGy3z+VOMSvB4gVT4reJm8BV4Jd/AuD4g4 dLPa+0Yj/qQ03xX1k5b61CHswAxD8HJzf7dMS56KKA9mP15N1sJTPoq5Bn/MAh5E9Btq BaZXNOZa4zfmL/I8zhGvY5aWk95CONkOUierAV7bCE1E8/NKdj31ug/KMVmv1E33wuWO fplw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1iJhMfxk; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c126si212149iof.49.2021.08.02.07.04.11; Mon, 02 Aug 2021 07:04:24 -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=@linuxfoundation.org header.s=korg header.b=1iJhMfxk; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236601AbhHBODc (ORCPT + 99 others); Mon, 2 Aug 2021 10:03:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:40742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235407AbhHBNzj (ORCPT ); Mon, 2 Aug 2021 09:55:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8ED59611C9; Mon, 2 Aug 2021 13:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627912446; bh=jI+YS/i+yRrMJsmjX9PV8o/kWoZul4RIIHZhNbtJnWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1iJhMfxkRi3Xr5Q4Mq8Rk6Xp4CsVnLbAPKnfBlilODGh/bi86kMzy4kMtUJHW9VOc no91Zg2+7PGNvV2u0EsDCVBcSL0zVqLdZ/zzFR7XS42v6bZlQoltV15eKZ5nSA6s7D 9rQ4vbOVvZu4ueYfxHBh88sg1Ut/jXLEwj6X9zqU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenz Bauer , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.10 29/67] bpf: Fix OOB read when printing XDP link fdinfo Date: Mon, 2 Aug 2021 15:44:52 +0200 Message-Id: <20210802134340.007690469@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802134339.023067817@linuxfoundation.org> References: <20210802134339.023067817@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lorenz Bauer [ Upstream commit d6371c76e20d7d3f61b05fd67b596af4d14a8886 ] We got the following UBSAN report on one of our testing machines: ================================================================================ UBSAN: array-index-out-of-bounds in kernel/bpf/syscall.c:2389:24 index 6 is out of range for type 'char *[6]' CPU: 43 PID: 930921 Comm: systemd-coredum Tainted: G O 5.10.48-cloudflare-kasan-2021.7.0 #1 Hardware name: Call Trace: dump_stack+0x7d/0xa3 ubsan_epilogue+0x5/0x40 __ubsan_handle_out_of_bounds.cold+0x43/0x48 ? seq_printf+0x17d/0x250 bpf_link_show_fdinfo+0x329/0x380 ? bpf_map_value_size+0xe0/0xe0 ? put_files_struct+0x20/0x2d0 ? __kasan_kmalloc.constprop.0+0xc2/0xd0 seq_show+0x3f7/0x540 seq_read_iter+0x3f8/0x1040 seq_read+0x329/0x500 ? seq_read_iter+0x1040/0x1040 ? __fsnotify_parent+0x80/0x820 ? __fsnotify_update_child_dentry_flags+0x380/0x380 vfs_read+0x123/0x460 ksys_read+0xed/0x1c0 ? __x64_sys_pwrite64+0x1f0/0x1f0 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xa9 ================================================================================ ================================================================================ UBSAN: object-size-mismatch in kernel/bpf/syscall.c:2384:2 >From the report, we can infer that some array access in bpf_link_show_fdinfo at index 6 is out of bounds. The obvious candidate is bpf_link_type_strs[BPF_LINK_TYPE_XDP] with BPF_LINK_TYPE_XDP == 6. It turns out that BPF_LINK_TYPE_XDP is missing from bpf_types.h and therefore doesn't have an entry in bpf_link_type_strs: pos: 0 flags: 02000000 mnt_id: 13 link_type: (null) link_id: 4 prog_tag: bcf7977d3b93787c prog_id: 4 ifindex: 1 Fixes: aa8d3a716b59 ("bpf, xdp: Add bpf_link-based XDP attachment API") Signed-off-by: Lorenz Bauer Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20210719085134.43325-2-lmb@cloudflare.com Signed-off-by: Sasha Levin --- include/linux/bpf_types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h index 2e6f568377f1..a8137bb6dd3c 100644 --- a/include/linux/bpf_types.h +++ b/include/linux/bpf_types.h @@ -133,4 +133,5 @@ BPF_LINK_TYPE(BPF_LINK_TYPE_CGROUP, cgroup) BPF_LINK_TYPE(BPF_LINK_TYPE_ITER, iter) #ifdef CONFIG_NET BPF_LINK_TYPE(BPF_LINK_TYPE_NETNS, netns) +BPF_LINK_TYPE(BPF_LINK_TYPE_XDP, xdp) #endif -- 2.30.2