Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp219384rwb; Wed, 21 Sep 2022 21:00:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5UXhlZeSor43v1T4qJ4fXuHAZsZmw2oyDLAS/TF659cT8IUraGOz6jxvj2UTIDW9KCD7IZ X-Received: by 2002:a17:902:ea11:b0:178:f0a:7472 with SMTP id s17-20020a170902ea1100b001780f0a7472mr1345464plg.46.1663819207345; Wed, 21 Sep 2022 21:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663819207; cv=none; d=google.com; s=arc-20160816; b=Kn5s/YAWb26rkiUHCydfIL8z2xhYgLD/6ntXeo+RxIEKLHY5w/ClUfs7s+X4yeXIE4 oQN+hr5REuJjVNyDm7NZoA/OvSyTTslL5e7GJak5CnIhhhtXDmdEd02F6oxHYULauUb5 uaO4wl3P+t96NctbRZRfeFj7+dGNZDwB/6aaGuIXiGyk8m0N90qPrJkp0mF6BoEG/s06 EjGGfczn8t5g6Jsalbp/znH1J061AVq3vexIyTWBD5D82C6IyxKKzcFSZ8fAnEdM+7bF FgpH1IOWPn5+jQ1Sp9gAElCimWz72FS/aqwEZlK5UUD+yb+9cBN845aS4lU/PtOVL92M dxmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XNbtSxfuJM0TvCbKrDSFlGazSHd4nOQHgC+9b6ylUe4=; b=BF+ZFa5muVu3TWXrqar1HRlTceB29OBkr1by0bEf63kXV+Oj9Oa3Kg0Y4trUpBPUiK pgrmdprncfDIloqycPyNIF23ktDh74FZmo+kej3fq+VZhhlEhdpNV5ZQkh8MXb2mkm3V HkFLzjWd0xAAsIr+BIgTMDgmxQH80FpFs+RwXE6km7MDevzt1WVr1lhRgROrdTN9WPsL UjlXVpjb9PXALbNVj+ujHfp42OfpJszTsAGH8uHK/o46RYXQ0LECebITViJVyBvQv5+A wg2B9hx/mHdS4eX24rsuvAl2Oblt+5BDeRKNTCWXJ/saCrKuHqBAEB5GUi7Y4jUzaySW V+8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JLTH01Kn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a170903120900b00177fd9637cbsi5583659plh.570.2022.09.21.20.59.18; Wed, 21 Sep 2022 21:00:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JLTH01Kn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbiIVDd5 (ORCPT + 99 others); Wed, 21 Sep 2022 23:33:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbiIVDdz (ORCPT ); Wed, 21 Sep 2022 23:33:55 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CF8A9A9EB for ; Wed, 21 Sep 2022 20:33:54 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id bh13so7912263pgb.4 for ; Wed, 21 Sep 2022 20:33:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=XNbtSxfuJM0TvCbKrDSFlGazSHd4nOQHgC+9b6ylUe4=; b=JLTH01KnBgmnNcpiE4BaxPSMUmiRK1wixqi2R2fDvpYZ7mbFuWVA+eCMwV9Ooy7Y2R Woa8XpodShi3pnIGGNpgTJfitVebcLwCm8c/U0JiK4sHYFoOL+kb1m3bgvOAeN7Z7r0W 00Y2KF+MivPazWmmeeTVy/Yh2IAp+53XXFWOs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=XNbtSxfuJM0TvCbKrDSFlGazSHd4nOQHgC+9b6ylUe4=; b=qIHEy5uEaH7UvkQGL8UpSjNT4UpSO9czD1c2BY+fCrefT7M0YOAvo15pOfvOJWCTsA GnoYx+/Q0FTtyFeWUmweGFH42oIzj0Un9n4YLLgnulmkJnFNHxD8XARCiiAKDmrEbnwy DNNwxX0Hn+ItIK2mY6QynfBy+Hmf6DteeMU77jh/In2UZ7GP4DTIv82iYZVANJjhA2w3 4x+kTfx69+rjGxlYYvMU7o3902hkqNS6oUFzTFlE7a3Mr3VscFEGgewEyr/oYIeaqTn7 Bc7i/pMURlXeo46MtbWACohoumntCvmUfYoO3CI7i3W6eNYjDvgM3b4YfQK8FG8pAL3I HHZA== X-Gm-Message-State: ACrzQf0VzneUsJvnzpvJFl7VGFSUk4Da02e8WZHOWCT7bBoFIOwg8QIl ZWt+m8ZCAe9H2ppAEdrVZGFBCA== X-Received: by 2002:a05:6a00:1889:b0:540:acee:29e4 with SMTP id x9-20020a056a00188900b00540acee29e4mr1550769pfh.49.1663817633640; Wed, 21 Sep 2022 20:33:53 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u9-20020a170902bf4900b00176ca089a7csm2754925pls.165.2022.09.21.20.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 20:33:53 -0700 (PDT) Date: Wed, 21 Sep 2022 20:33:52 -0700 From: Kees Cook To: Siddhesh Poyarekar Cc: linux-hardening@vger.kernel.org, Miguel Ojeda , Arnd Bergmann , Nick Desaulniers , Nathan Chancellor , Tom Rix , llvm@lists.linux.dev, Juergen Gross , Boris Ostrovsky , linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/4] fortify: Use __builtin_dynamic_object_size() when available Message-ID: <202209212032.5F392F42@keescook> References: <20220920192202.190793-1-keescook@chromium.org> <20220920192202.190793-5-keescook@chromium.org> <9d80e0a3-3fcc-0676-4529-79743f418557@gotplt.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9d80e0a3-3fcc-0676-4529-79743f418557@gotplt.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 21, 2022 at 07:43:17AM -0400, Siddhesh Poyarekar wrote: > On 2022-09-20 15:22, Kees Cook wrote: > > Since the commits starting with c37495d6254c ("slab: add __alloc_size > > attributes for better bounds checking"), the compilers have runtime > > allocation size hints available in some places. This was immediately > > available to CONFIG_UBSAN_BOUNDS, but CONFIG_FORTIFY_SOURCE needed > > updating to explicitly make use the hints via the associated > > __builtin_dynamic_object_size() helper. Detect and use the builtin when > > it is available, increasing the accuracy of the mitigation. When runtime > > sizes are not available, __builtin_dynamic_object_size() falls back to > > __builtin_object_size(), leaving the existing bounds checking unchanged. > > I don't know yet what the overhead is for __builtin_dynamic_object_size vs > __builtin_object_size, were you able to measure it somehow for the kernel? > If there's a significant tradeoff, it may make sense to provide a user > override. So far I've not seen any measurable performance difference, but I just may not be creative enough yet. So far, the tunable is building a kernel with or without FORTIFY_SOURCE and UBSAN_BOUNDS. :) -- Kees Cook