Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3081633ybk; Mon, 18 May 2020 17:27:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8Ita/RgCd6op64V6UETpVjFqfEAnOw0izQ1+sPA1MvLIA6tdPJrtgeEPlNqX8vmSl+xIy X-Received: by 2002:a50:abe3:: with SMTP id u90mr16100110edc.278.1589848063915; Mon, 18 May 2020 17:27:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589848063; cv=none; d=google.com; s=arc-20160816; b=LEdZeIEXXbEonALFBOiERow8cww9Z/BSUjWV+Mr6SBPXtnBt5UdLmjjRpz642+KC/4 hzpdNtWPO3FLQJUzGkgZXHzLJyG+dZsiMZBuQNAnvVCcDge2j7OhCkbvoYBvrERWy5hd mCZbzQOLDh+rDhxN8brJVwYTHEEGKBCPm+m6EOgcRD/GK59JzqmJOZnHBiNWGSB+xhU6 l9UGsqwObw792OZ/8APBTtpcrOcipmOSi87DyxraDVI/RXD4AsxGsy2laSjnPFTgDSov A0muv3MWQKItSXi8LtsNIaSub0jpWn3CY2M0GTDJbzleytCQMoM/teiJgmPHezWr+o4x UIEg== 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 :in-reply-to:references:mime-version:dkim-signature; bh=6nQAIsGmbBiNV1zSsJWz0TENOrH6776bbwZuF8Trr/w=; b=pGy9DXQCI54Ieb5fJnHjVKh71n6RER5blwdzyL72g/eXZg3S8VfCloZGvYVahHEWyJ lQyEKhjGGzYuIBJX9ScAj+s1YYFGV6I5klT7TeMS6AwkZBtXoO7v/xbfBwojHppask+A MGVLagkONPl5urHHHWCKIGP769e4/LAHmNBI4YMXI1hBkQny2sjdAhpwkFTt8NopXLr5 IvpuhVyugPZMibQiqelcNh1cUAib3e7giYBl5X/96iz4qcg8+1W4Z9A0EARTdgCR2Hkr VCx+/CENcjwRdHl4i14qnajFX1kRdT35zai20AagQ/WyubataD8QLBpdqf8/n4vm4NdN yBVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="PuB7x/uV"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id aq18si3823779ejc.123.2020.05.18.17.27.21; Mon, 18 May 2020 17:27:43 -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=@gmail.com header.s=20161025 header.b="PuB7x/uV"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbgESAZk (ORCPT + 99 others); Mon, 18 May 2020 20:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbgESAZj (ORCPT ); Mon, 18 May 2020 20:25:39 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69063C061A0C; Mon, 18 May 2020 17:25:39 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id d7so9740796qtn.11; Mon, 18 May 2020 17:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6nQAIsGmbBiNV1zSsJWz0TENOrH6776bbwZuF8Trr/w=; b=PuB7x/uVjj+wZ/Gxit6ndJAZ2p1GOG41RE3fdhvuzB3KG3w1MrvH1AbDzwTBrI+OTg 3qlFSI/J7tqm0sQzs0JKdBholOEQl5vDk9J8gEyowujMKD+xSbp15FX10gXg2rs+9N4/ 15Qw+H+xeMeYCziG8zL48HeAJOISggk/T/BCCZD5qCP0Rc4U2rdcktZRudMN9NndwVG/ MBSovAoMGGZXRzHbXEdGGSKtka3KBnGf8kJ3JhVu+DXuP3mdzQ0PKnzNV3LLrURgqcSG pCUq9CBCQ0pErIWy7cV+APAwi7ObeXfRIXnqAlNR5XfocyfJ43KTrjbs2x7RGEPqcKd+ C+Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6nQAIsGmbBiNV1zSsJWz0TENOrH6776bbwZuF8Trr/w=; b=qfFgQMcfEDXig+jaxgZb0JoVXz8djD9DycH4LztP1jZJu5iGVhYnhaS5iGOo4JQz1u 5L6S51E7LwhWE9iUTWA8/2LnAtAcKn4EA4gi8UylYMB01OgkXQn4dPBHkUewswBHL324 7fU57mVNAeGmVqKVbZ5jGSg3aZDu1KKVLasmKSl7fzYP5pjBMZRaHgjoUHbBVMUAYGKD rCNyTcXX6qRAJXKOecUcFYFkjPPr5aCCQZfaaLVekdSpcFSVRK+gEpzvLPk7btT2/eju /Fj5QotY7j27cqJU7C9RweRsDNOBSkuq7z4xzjcevyxwrZpmKJ+8rc60zwaKvAbdEFq2 907Q== X-Gm-Message-State: AOAM533jPtUbVqWpjFOML+Qf66VZ/47Q4IJltQVeLgNWNJFQddSE8m3H R30plWTig35KwoL1w1lwygQtS+aWEzB4FzJ0I0g= X-Received: by 2002:aed:24a1:: with SMTP id t30mr18426331qtc.93.1589847938662; Mon, 18 May 2020 17:25:38 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andrii Nakryiko Date: Mon, 18 May 2020 17:25:27 -0700 Message-ID: Subject: Re: UBSAN: array-index-out-of-bounds in kernel/bpf/arraymap.c:177 To: Qian Cai Cc: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Linux Netdev List , bpf , Linux Kernel Mailing List , clang-built-linux , Kees Cook 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 On Mon, May 18, 2020 at 5:09 PM Qian Cai wrote: > > On Mon, May 18, 2020 at 7:55 PM Andrii Nakryiko > wrote: > > > > On Sun, May 17, 2020 at 7:45 PM Qian Cai wrote: > > > > > > With Clang 9.0.1, > > > > > > return array->value + array->elem_size * (index & array->index_mask); > > > > > > but array->value is, > > > > > > char value[0] __aligned(8); > > > > This, and ptrs and pptrs, should be flexible arrays. But they are in a > > union, and unions don't support flexible arrays. Putting each of them > > into anonymous struct field also doesn't work: > > > > /data/users/andriin/linux/include/linux/bpf.h:820:18: error: flexible > > array member in a struct with no named members > > struct { void *ptrs[] __aligned(8); }; > > > > So it probably has to stay this way. Is there a way to silence UBSAN > > for this particular case? > > I am not aware of any way to disable a particular function in UBSAN > except for the whole file in kernel/bpf/Makefile, > > UBSAN_SANITIZE_arraymap.o := n > > If there is no better way to do it, I'll send a patch for it. That's probably going to be too drastic, we still would want to validate the rest of arraymap.c code, probably. Not sure, maybe someone else has better ideas.