Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1162153pxv; Fri, 16 Jul 2021 03:08:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+op/zzzmTqTN4bkEvHgdLvF2lqvc2zrXp7vFZioJpvVTI77dpq4eyKEz/dP8WMIt+pzqE X-Received: by 2002:a05:6e02:1a8b:: with SMTP id k11mr6203197ilv.136.1626430128656; Fri, 16 Jul 2021 03:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626430128; cv=none; d=google.com; s=arc-20160816; b=GFshVF3fddzQ/5aYybVePvpvmVUEqCtBjIKv8BBIF0glPFiA2eJ68HpF/aNbCwyNeL bajraaP511FmeOC1Kage49yP6Cb6EvM9HiHpBsE+H2vO/yLumG3TtZ6Hv7NhhIxn/JMN FutKcQzdFmM+iyyzjVAV3VoFfw1RSeVzlRvDt7DMliyRq7MSexKQiee0F+Q289gVtAA7 hyc9ryu4KOwbjPxXcRx4/FP4NudAVnuVXmoPcmGBUnpPId0t5HsyfvIujI4w48KdSJpf CIaIqq9aCRA1Sz7q/ZTp02/QSSKgkX3RRY7Bj9qjYi9bQWY0CH94gQ0OvTcEb3OXxEdX NaBg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=MCp/pg+XuWbTvMrNcAeNDWuWAPF6IPK9geF9Qe+H510=; b=Rkd6VVwuiyZEdL5A4XRHorlHJFvsQxHmfMHATlc/ffA0z8DHYBeeSzKqZcuHo7bm7v 9BYfsmZPrncARalkZYjZUhJnYJPsiKG0b1qxuXV19Y6xwwETA6g0ityuySUbeTN3y8SY K5e4v+ZQSBN8X8yEUwuR9U+AxsM1FgochOqJnMl9eB4bk8SNxPP5YFII6s8U8fy84/g4 0BqQGMCxLTXUVffIyojN63E2wH0ZtF5FFEZyYwLt2uJ18chlfNkd9xj3F6/OpgaEoPbm SSlmmaguB8dO5QLtcCjYKR7Dm/ZoijOnf+vY/ujYSQpQ/qnd7xwit783O7xbKGTzi5l8 exoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=hAZqa8UO; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si9424886jaq.116.2021.07.16.03.08.36; Fri, 16 Jul 2021 03:08:48 -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=@cloudflare.com header.s=google header.b=hAZqa8UO; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236772AbhGPKIp (ORCPT + 99 others); Fri, 16 Jul 2021 06:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236579AbhGPKIo (ORCPT ); Fri, 16 Jul 2021 06:08:44 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE6D8C061760 for ; Fri, 16 Jul 2021 03:05:49 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id f17so11431824wrt.6 for ; Fri, 16 Jul 2021 03:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MCp/pg+XuWbTvMrNcAeNDWuWAPF6IPK9geF9Qe+H510=; b=hAZqa8UOO4TXGs/6z/CGk67n27e/Y/5EuFmH48DrwxhBe52aZGQuzi3R/wIjOY2SU+ 15AHQtjhc/TcuXKCYZ20EDfDYOJhLSaJi6mO2nugyCs/A1tpCAGQlLCnhpN8A7/FyN7B gfkTgsh4jmeg/Sg0x9XgFvjKJlNk0VZAUAoI0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MCp/pg+XuWbTvMrNcAeNDWuWAPF6IPK9geF9Qe+H510=; b=eA0wrU5r8AGW/VPDTjfSd+X9DiE1JmGSCxPRX0JeL4hL08KasnJZ2JNR/ryovnmXOS B2PPPOMwCv7gmbI3ztRT+ijxXzAs3IkCqfXCtX7Q83ZK6k1VWeXOMtqsgziudU2QcgJI deG/3mWbRo8QaG+G3LoRVKai3FhdonCzgdLHwiPs6m1PPH5diUVZM3w1dABuR4FWUPOV 4RHKzjjzsj/8IGvSjzvJMSpeG1yxE0ZH51KYAWqeBsI7jz+AyM0bjA2vEIea2YJCPMfa rBPyokcE+O2dJgZmqNsxB9utXza9cenQ+0vmc40j5CaQ3wHztiuBDP3bZ3dSNU8rxDd2 hOmQ== X-Gm-Message-State: AOAM533OIPLu0KziZzreXs7VcqOZaGCGSVisenQtNr6ySdPJ4k2K/8Yz u044Mb1KultXLNriJ2JEPkbE2w== X-Received: by 2002:a05:6000:180b:: with SMTP id m11mr11367626wrh.6.1626429948500; Fri, 16 Jul 2021 03:05:48 -0700 (PDT) Received: from antares.. (c.b.2.6.f.3.0.0.d.9.9.9.a.0.6.5.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:560a:999d:3f:62bc]) by smtp.gmail.com with ESMTPSA id l14sm9130706wrs.22.2021.07.16.03.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 03:05:48 -0700 (PDT) From: Lorenz Bauer To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend Cc: kernel-team@cloudflare.com, Lorenz Bauer , Andrii Nakryiko , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf] bpf: fix OOB read when printing XDP link fdinfo Date: Fri, 16 Jul 2021 11:04:52 +0100 Message-Id: <20210716100452.113652-1-lmb@cloudflare.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 a9db1eae6796..be95f2722ad9 100644 --- a/include/linux/bpf_types.h +++ b/include/linux/bpf_types.h @@ -135,3 +135,4 @@ BPF_LINK_TYPE(BPF_LINK_TYPE_ITER, iter) #ifdef CONFIG_NET BPF_LINK_TYPE(BPF_LINK_TYPE_NETNS, netns) #endif +BPF_LINK_TYPE(BPF_LINK_TYPE_XDP, xdp) -- 2.30.2