Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3116204ybk; Mon, 18 May 2020 18:32:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZlwfOP/UJPiojlWgK/tB9oIhokDIt9EhK9kCGx+XmrXbsLCcdzwBibcbmZe1OfT7inQ0P X-Received: by 2002:a17:906:1313:: with SMTP id w19mr15576677ejb.79.1589851941157; Mon, 18 May 2020 18:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589851941; cv=none; d=google.com; s=arc-20160816; b=lU1cQ9675KV3vZ5QeG6dnga8aSaAMRhYXdYqahRreJbilBsqI827sfotE6BFLVMuNv j3GuvAlPL0hFzmei6lSPZ9TbeGKLPQ3XJI1CfY/03Fw4Ha9Qvz5k3mRUI+dfOQfPxwJP LhrKvg94K/Y4qOMacXaqABV+KyYNSVElAJawAs7nYT1LaCUgJx7NUiRh4Dw1WKmlEqac x5REhY5jSiNhlHoMe0+ATq6lVcqM+bSYoCtjjLF8p5My4FR3dTCVxuJcxGf1OHNYncMd Li9TxWTaLLmmG4jnqDJUVsHC9MVF4D0bOu6/IpbYG4jGllfrMxp+mSd2tn1QQMu3Ar/T fmbw== 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=dKVPJF/NEdnmBXWDMMPJJBCWq4APWNkeLoswoZMG3Ww=; b=yq6FNFFffpFXg+YIf5jlXZyXmguqkgPgVziI1uJ1vlgEZcuzOEXoUqkVEIriTrqywv xZQhF66gZmp9dhCN7FSV7XRYtReMgGKXGetXzvk4l6vXzRAtbmGHhBd5Z9aztnMf8Mvs gWkwc0ojop1zEP6WkuUPYSunf8sq3IZ0pJze6/x6olrFful6mE4gRAEv4XwLhZQS3q5e 0vU6OvwhU2CiG6EVtiRyebv/tSSAA9QFpVZTLqEUGF2KhC2zvr8qi92KZ2Bgd0UAVyUo 6AGuFPnGNaa+ai5cd0lLGyIlQciUIdS8phMW7yL4jakiZioQW7Lws/93/28LOTOohsay jSwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I75n233f; 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 g5si7344703ejs.290.2020.05.18.18.31.58; Mon, 18 May 2020 18:32:21 -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=I75n233f; 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 S1727981AbgESBad (ORCPT + 99 others); Mon, 18 May 2020 21:30:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbgESBac (ORCPT ); Mon, 18 May 2020 21:30:32 -0400 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1AF9C061A0C; Mon, 18 May 2020 18:30:32 -0700 (PDT) Received: by mail-qv1-xf44.google.com with SMTP id dh1so1874872qvb.13; Mon, 18 May 2020 18:30:32 -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=dKVPJF/NEdnmBXWDMMPJJBCWq4APWNkeLoswoZMG3Ww=; b=I75n233fSllmNqXPDvlYaKSzbi9lYJnoYrDss99O5N5J83UuSJ/DxQY+YqNsWWGKY6 4nbbPnTvENBt04qqdbjofYwUwQPUsHSyjZj5zviEWx5HPBHx6MAvMSgXwy0IM7C3Vq/4 KakPFaUf4vfhQJ1h039eq5zTM2f6UkNWa+BOiXTaxIkFhuJOHPruDh5sVcFz0L3Xp32G KFo4K1L4v/hrT/UuuMwR5rsodFFR3Loe1OHWPjnXI0UIvOL9azOyAzhrC/GwU0XI6JIX DNC0C1pGBenK+qCtFlxQjIDN88Xdwh21c7W/2QV89PTOKrvMIpmi7b1I6MEHCLBGFy0u X7BQ== 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=dKVPJF/NEdnmBXWDMMPJJBCWq4APWNkeLoswoZMG3Ww=; b=pW/mTdrUVje8Dys2rtzgw1iMV1t1BA+z1cJqutIW9ByY4qPkfF8xc83QSvzLW04Wt7 L0IefGSIQkRFumsd3AqIDcjyQ/H6e7P3ZuMxPZm5t0hOjDagbN5XS4BVV/0KYsHYrhVR /c25emBBera7cOsB0j3flW60pX01PYT79sHOYIM0Q8x3kA7cU3oibzeJJw4nMjCyrBvU 6ufIem9bsrkJkG//f8oql5D8xHWNjgye3C0tFh3yJSfzc+qD5z9fT5wFI4O8ENyOwakx PaqVkxHX4lGxftMoLpoiMhjDRR4ZZE89EkizaYFyZd2JWUFGbnS54E7JhM4TBdjigmgy Ccxw== X-Gm-Message-State: AOAM532u40N96O+y1aOg6EMCFdHBRhiVP74ix0LFfGAUWh2KjL+hFevP hVFMHHGF+EsRhQuV6IQgHu2Kq5J6E9gJEIy4jds= X-Received: by 2002:ad4:55ea:: with SMTP id bu10mr19629870qvb.163.1589851831727; Mon, 18 May 2020 18:30:31 -0700 (PDT) MIME-Version: 1.0 References: <45f9ef5d-18e3-c92f-e7a9-1c6d6405e478@fb.com> In-Reply-To: <45f9ef5d-18e3-c92f-e7a9-1c6d6405e478@fb.com> From: Andrii Nakryiko Date: Mon, 18 May 2020 18:30:20 -0700 Message-ID: Subject: Re: UBSAN: array-index-out-of-bounds in kernel/bpf/arraymap.c:177 To: Yonghong Song Cc: Qian Cai , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , 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 6:00 PM Yonghong Song wrote: > > > > On 5/18/20 5:25 PM, Andrii Nakryiko wrote: > > 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. > > Maybe something like below? > > struct bpf_array { > struct bpf_map map; > u32 elem_size; > u32 index_mask; > struct bpf_array_aux *aux; > union { > char value; > void *ptrs; > void __percpu *pptrs; > } u[] __aligned(8); That will require wider code changes, and would look quite unnatural: array->u[whatever].pptrs instead of current array->pptrs[whatever] > };