Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp292342rwb; Thu, 22 Sep 2022 18:23:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM50NV4YPC74TnOaUfaVlXrUjv2ogJCnJLPg+qahTXyfVyboprdwRgsyeJ9kGCjzIHNnsVd1 X-Received: by 2002:a17:90b:3a85:b0:203:214d:4288 with SMTP id om5-20020a17090b3a8500b00203214d4288mr17789501pjb.183.1663896215150; Thu, 22 Sep 2022 18:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663896215; cv=none; d=google.com; s=arc-20160816; b=ul+9ZSwsRXCCUip5MNZGW+SEvXBL/T3u23RN3hfq9czFXEnvUBQs1bZFBQbcPQdSX0 qMm/MgYerUBZ9sTR/EC+ksE6JrSXPMZ62BlIZXnfkA2ZMBYeXxkInCGFvlQcsFQ1kIJb NQSjxWLvtswD/sHqdWsPppLf5sGy8zQG5amQnvy/SdKcI81QFVVKKGBYkuDFaAtTYbbO BJi522LvxfuC4zh3+5Y4cwcJH1eCNhZEKncILbYFZ8SgobXzTWYEOeSIaHve3IoGsGFR OP+ZQ8ra1hXZYndTOr4Id4P1M9yC3Bn+NYYPYawV9A/nZPaztF7fvGUUG1/oEM5jRW2a 4tSQ== 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=fE8nCD0AAGL6m11CnMBfi2PNly3cqHNqiT4DGj6b5Gc=; b=PvmLxq/WROm5qAcvsDRAUg4yNHmnwx4rwIQ0eCUJadwtzcN5D6dYs6ywUYaX2/aEwd wGjrV3rAk+s6XHuTRGXr7LdhjNiQtOEJ2EGgZc9NmAzxUK7OOiwhac2DYVUnvE3XkC6/ 0BTAMo5P8So6T20XeHXX9keB7a4E3zH5rVT6jIpOP/2eDpYFauxstORySJ728oxbC0sP SVi+cBf8RSwpvuLvYzgz+HuM8tPSoQq+xQ1F0+4ImjxKg3+zBOamCM43b4cfVISEBXPx jJTekSzPec7517Z/Fv2KrBLHNUAl05Ar7XJIOllei2ZQIAJ45j8YALT//SbGyVjeKUwo qfHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZcgEPa5G; 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 y30-20020a056a001c9e00b005182fda1b23si7334323pfw.236.2022.09.22.18.23.22; Thu, 22 Sep 2022 18:23:35 -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=ZcgEPa5G; 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 S231215AbiIWAU6 (ORCPT + 99 others); Thu, 22 Sep 2022 20:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbiIWAUz (ORCPT ); Thu, 22 Sep 2022 20:20:55 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1937DCDCFB for ; Thu, 22 Sep 2022 17:20:54 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id q3so11379348pjg.3 for ; Thu, 22 Sep 2022 17:20: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=fE8nCD0AAGL6m11CnMBfi2PNly3cqHNqiT4DGj6b5Gc=; b=ZcgEPa5GX4lJbCqdaQIoVzgDaAGB2ncYfRY5U+Q2yAy9IywhwFoEoy1uuMIfswt3ny 794u3NbJDIPlXO3iAM9o8Z2XldjYuBr70GXIXXMpFKlmSoVyLitAOvWbioDxzj83ipsx dnX65KS5JpCN9hZliXHZZTTpOarXoM17UEoGc= 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=fE8nCD0AAGL6m11CnMBfi2PNly3cqHNqiT4DGj6b5Gc=; b=iXFFv8Dise1WvyzbY3c3hdu0f0Rn3sh3mIiwjxD2GzpZXTkSJ+buQsg6neoMqscnvR ddBGn2bbPVptrDH66ecmcq9yWY8BEMaRjtpKrkxCtmjKsKLvNuOnZZRZKKoH30dY2Xxj x0pSgKOKNsaoExzdKbOR6GyanqRnLn7sndQi6efelIAE0P2koXsQWXIHZ9AaBae+FTpA 1oNe9SjKNIQsqBX2YrroxG03DUGbXmJLzXR30/viTtVWZgfKygjMWLs04rF2nzVAQgbf yRpq8gdRppoqRbNXEEZiWsNDruKVkhStmJ0C81fzqFVxRUe+u1ZySa6txgfgfSV0H2Bx 71Qg== X-Gm-Message-State: ACrzQf3ZP7Ih+XEKS2eAAzuOISrIlAIiT0ctS1nyqLKu1vGasJrH64/d bT4G15ZD6/KYcnoryQQYrTgKtg== X-Received: by 2002:a17:90b:4a85:b0:202:4f3f:1f65 with SMTP id lp5-20020a17090b4a8500b002024f3f1f65mr6397691pjb.241.1663892453590; Thu, 22 Sep 2022 17:20:53 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k60-20020a17090a4cc200b002006f15ad4fsm378261pjh.10.2022.09.22.17.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 17:20:52 -0700 (PDT) Date: Thu, 22 Sep 2022 17:20:51 -0700 From: Kees Cook To: Siddhesh Poyarekar Cc: linux-hardening@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Arnd Bergmann , Juergen Gross , Boris Ostrovsky , Tom Rix , Miguel Ojeda , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH 0/4] fortify: Use __builtin_dynamic_object_size() when available Message-ID: <202209221714.1D792FE6@keescook> References: <20220920192202.190793-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu, Sep 22, 2022 at 04:26:54PM -0400, Siddhesh Poyarekar wrote: > On 2022-09-20 15:21, Kees Cook wrote: > > Hi, > > > > This adjusts CONFIG_FORTIFY_SOURCE's coverage to include greater runtime > > size checking from GCC and Clang's __builtin_dynamic_object_size(), which > > the compilers can track either via code flow or from __alloc_size() hints. > > > > FTR, I ran a linux build using gcc with allyesconfig and fortify-metrics[1] > to get a sense of how much object size coverage would improve with > __builtin_dynamic_object_size. With a total of 3,877 __builtin_object_size > calls, about 11.37% succeed in getting a result that is not (size_t)-1. If > they were replaced by __builtin_dynamic_object_size as this patch proposes, > the success rate improves to 16.25%, which is a ~1.4x improvement. Thanks for check that! Yeah, a 40% increase in coverage is nice. :0 > This is a decent improvement by itself but it can be amplified further by > adding __attribute__((access (...)))[2] to function prototypes and > definitions, especially for functions that take in buffers and their sizes > as arguments since __builtin_dynamic_object_size in gcc is capable of > recognizing that and using it for object size determination (and hence to > fortify calls) within those functions. Yeah, this could be another interest set of additions. It seems like it might be more "coder friendly" if, in the future that has the __element_count__ attribute, it could be used in function parameters too, like: If we had: int do_something(struct context *ctx, u32 *data, int count) this seems less easy to read to me: int __access(read_write, 2, 3) do_something(struct context *ctx, u32 *data, int count) as this seems more readable to me, though I guess the access-mode information is lost: int do_something(struct context *ctx, u32 * __element_count(count) data, int count) But yes, this would be excellent to start adding! -Kees -- Kees Cook