Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2379864ybk; Sun, 17 May 2020 19:46:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwscufmF18NeOYhvxXisdj8Z+Thyxx1sqgeDfOMST3KvRKbp59wmq42Ha2KqutGypBD5Xj X-Received: by 2002:a17:906:c108:: with SMTP id do8mr6318192ejc.134.1589769983617; Sun, 17 May 2020 19:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589769983; cv=none; d=google.com; s=arc-20160816; b=jO7tN5l5Nqrdb57DflPwI0yBgqnSXgj38js51dgYPzGGivE6Ab2f3mN1McWeTkHFIE nNdK0iGCDLRuPWUUP4PZiNKhR+EopR7aZnFqyLQaN9ceqkYU1JR8IgOBt7Pd0l/lH6dk cR+sy4l0XlT8eL0ol1RTJ40mMhKWFCkfZgJkahLwjij3llW6DZcUE0Ux3+uONPPoRFcv wVtEE3QnZ1MkzSmnQ3VlGF7uZR/1Al+bNPI6WlJY5bQXLXWzbvByr/8YWASqB6cmPmou Uah/0I77QwxPSm1KbzBoqBnROLRGAHJvwnGBluwwDaXRlKC5HpI9WEYuDNWRjkGKlVYq w/GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :mime-version:dkim-signature; bh=8K0sJqpLsIUnKAf2a0bGvl0VcjUMX3pFm+WYrpBq63U=; b=G3ORqZByEf8GcC/Us1tl0zZcV2PO4f7q/jurqXWItIO/5MMTyr7tYhY6q3LkKTPuDC l5cSlTJhZDLpPkPR8ZGT893Z3ty4M+6D1J/PsJ76sJjCPmQiGoDPG1owiZe1FicFZp7C 1P/qXDeVxt0782OUA1vJV/K4O7Y2RBCXFNr366GFOTUzcLJC4Cagx/ihwDsp7nE/UdsA ymPdlXWYxTFmFDZkxmQ2bsTMHMoOlA5UZ9nFhBiPb9sNA7iX0got/N1fSxqZUrB0KdHM 7szCfK/JL7pSWZq4D1fWBVltyVJlZxg2czxw1MoF7xql+Liddom7MPujXncGp9B6zMHZ 7lKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=bal608dP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q19si473445edc.439.2020.05.17.19.46.01; Sun, 17 May 2020 19:46:23 -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=@lca.pw header.s=google header.b=bal608dP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726732AbgERCoo (ORCPT + 99 others); Sun, 17 May 2020 22:44:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726639AbgERCon (ORCPT ); Sun, 17 May 2020 22:44:43 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97D9BC061A0C for ; Sun, 17 May 2020 19:44:43 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id s21so7592750ejd.2 for ; Sun, 17 May 2020 19:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=mime-version:from:date:message-id:subject:to:cc; bh=8K0sJqpLsIUnKAf2a0bGvl0VcjUMX3pFm+WYrpBq63U=; b=bal608dPtmHgZjr230fo5HEIQmZpWNKbe748W5U7xWtCbMjZR+nm3oALJ/HWSvd00x 83Wr8YV8MLCO4AybYUDW7NOBlyfw1CrXTNq0We7cDoJwgzwt3P6Lz+g7EDAp9PxqyPXv i3ImAkB3WHEXwi7X6SfYulCiLO1feN+hFQhesKRoawqlcX7mtVgElmQ56aZ0asEczKmB hBUVItIYqiY+w0vbptHflC6eieNVeHjtNd3dShU8xW2hAnKqy7ZLWe5vl9vxhCAhQBoy yNLIx++JyjzrrmoSnZ6lGx7w/q0GB2d/ld+CzDsrU/X2eU4wIBOh9WPL4rw/0kM/6RNx YByA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=8K0sJqpLsIUnKAf2a0bGvl0VcjUMX3pFm+WYrpBq63U=; b=Ozwbk2eOylS4VH3/kbGHWiy+DODhYgBmlxALmdWoICYJ8e/kj8Brt6MJYlMbviLJe0 EBNJcBU618YxvDfawyR6NtfoKksLjIA8e7aACnzE5Hr3lS7TeS34fwCGwKD65ytfWw/a RYIHV0KwavrWSzCHqzth9qyKdhqB2WGJOuFRreJSedhRCUDh199upvS6xwOgNN9qOJy9 OYxWs79QK/C6z5eJEmVj1vBg11E4u5gtmjSE3PoWSwslJcxdkTcUi1ToxeDqMsBhdQ9L JDpEByV0Gd2IRD2QZ5Z/og8wvDP//5hGzSEdT8bT7q7kQQQZaxh2hHWNmnZM2hS4Ivn2 zQhw== X-Gm-Message-State: AOAM5333GTUF9yuJ6CWZHTXWH1AJNirP3tMS7fqbvkskSaV4X77HyW5C sepTlq23nKCiEvJFNBHEv7uZqX+rXmT/toXx+D9rKA== X-Received: by 2002:a17:906:3952:: with SMTP id g18mr13610750eje.191.1589769882137; Sun, 17 May 2020 19:44:42 -0700 (PDT) MIME-Version: 1.0 From: Qian Cai Date: Sun, 17 May 2020 22:44:31 -0400 Message-ID: Subject: UBSAN: array-index-out-of-bounds in kernel/bpf/arraymap.c:177 To: Alexei Starovoitov , Daniel Borkmann Cc: Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Linux Netdev List , bpf@vger.kernel.org, Linux Kernel Mailing List , clang-built-linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With Clang 9.0.1, return array->value + array->elem_size * (index & array->index_mask); but array->value is, char value[0] __aligned(8); [ 506.031548][ T4134] LTP: starting bpf_prog02 [ 506.125326][ T4352] ================================================================================ [ 506.134603][ T4352] UBSAN: array-index-out-of-bounds in kernel/bpf/arraymap.c:177:22 [ 506.142521][ T4352] index 8 is out of range for type 'char [0]' [ 506.148613][ T4352] CPU: 222 PID: 4352 Comm: bpf_prog02 Tainted: G L 5.7.0-rc5-next-20200515 #2 [ 506.158632][ T4352] Hardware name: HPE Apollo 70 /C01_APACHE_MB , BIOS L50_5.13_1.11 06/18/2019 [ 506.169084][ T4352] Call trace: [ 506.172256][ T4352] dump_backtrace+0x0/0x22c [ 506.176634][ T4352] show_stack+0x28/0x34 [ 506.180666][ T4352] dump_stack+0x104/0x194 [ 506.184877][ T4352] __ubsan_handle_out_of_bounds+0xf0/0x120 [ 506.190565][ T4352] array_map_lookup_elem+0x90/0x94 [ 506.195560][ T4352] bpf_map_lookup_elem+0x48/0x60 [ 506.200383][ T4352] ___bpf_prog_run+0xe9c/0x2840 [ 506.205109][ T4352] __bpf_prog_run32+0x80/0xac [ 506.209673][ T4352] __bpf_prog_run_save_cb+0x104/0x46c [ 506.214919][ T4352] sk_filter_trim_cap+0x21c/0x2c4 [ 506.219823][ T4352] unix_dgram_sendmsg+0x45c/0x860 [ 506.224725][ T4352] sock_sendmsg+0x4c/0x74 [ 506.228935][ T4352] sock_write_iter+0x158/0x1a4 [ 506.233584][ T4352] __vfs_write+0x190/0x1d8 [ 506.237874][ T4352] vfs_write+0x13c/0x1b8 [ 506.241992][ T4352] ksys_write+0xb0/0x120 [ 506.246108][ T4352] __arm64_sys_write+0x54/0x88 [ 506.250747][ T4352] do_el0_svc+0x128/0x1dc [ 506.254957][ T4352] el0_sync_handler+0xd0/0x268 [ 506.259594][ T4352] el0_sync+0x164/0x180 [ 506.263747][ T4352]