From patchwork Tue Nov 1 22:33:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13027552 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA582C4321E for ; Tue, 1 Nov 2022 22:33:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E49C06B0074; Tue, 1 Nov 2022 18:33:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC52C6B0083; Tue, 1 Nov 2022 18:33:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC9406B0075; Tue, 1 Nov 2022 18:33:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 916BE6B0074 for ; Tue, 1 Nov 2022 18:33:24 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6DDEC40290 for ; Tue, 1 Nov 2022 22:33:24 +0000 (UTC) X-FDA: 80086325928.14.A46955A Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf04.hostedemail.com (Postfix) with ESMTP id 1A91140006 for ; Tue, 1 Nov 2022 22:33:23 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id q71so14658834pgq.8 for ; Tue, 01 Nov 2022 15:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=x+sHrlQ9qvuRyCEzJ8tyDL/yT5sTtV33z7B4OVR3Ags=; b=VWzODwGPwt0P786JMKNB4yVGgg435fbGV5qvF0tmnQZII/lvioB+5rfM0gRtBFapW1 B2Vt/r/3hyQ6HQ0e22x8QpWlhQo6UZ3+azXSonzC2/wasN2zwz6Ey6tb0roh7kfcuc/7 hHSrSR8gSyYdmcN4l4vDBHr21bm8P7XgVPAcw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x+sHrlQ9qvuRyCEzJ8tyDL/yT5sTtV33z7B4OVR3Ags=; b=73TZ7HzQwiSmOmahRfD2kq+lIcYy7Vjvg+gm1tYwrmMQvjE9ElhIk6nCW+D/FLn6/R DRuVVyxvFZAj8w5HqgKBJ/eFwjxNBQoJOaeuz45IDg+c/64SkLbVOA9eqtF5moTr+0jr GRaasV98YLcmxDZP++JtLa6zpBGNJMeTi7Lbsf0MfhJOnZwDyXZYenQOzJpWrJn8jqXu gkOm7XPTk+bGjIGYxsrUMfn/YI8RPCyxN3IBd7Od8RK6ob0JGa8qLWK1nUEV90q4juIi 5X59XkSwHMBjU/sAIf3Wh6ccRW4TcMY+IYwetSSl8J4GPRSGWVGqdafC9apUwZYZZxaf v/Qg== X-Gm-Message-State: ACrzQf3Vh9cmi2FGDxI8tScI4wgdXiKEYIx+hVoz980dOmsNNAW7ILPu nBCMgtjSJt8Ib2Lui+KOviwSFw== X-Google-Smtp-Source: AMsMyM7KiRxTvIICY6tEp0nx3mTQFcRJ7O18gSx0rrAXVMG55RZwUpbOc9W4hmimCcTWvdvZUIHzEQ== X-Received: by 2002:a05:6a00:27a0:b0:566:9cd9:3843 with SMTP id bd32-20020a056a0027a000b005669cd93843mr21970210pfb.17.1667342003085; Tue, 01 Nov 2022 15:33:23 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t16-20020a170902e85000b0018658badef3sm6866072plg.232.2022.11.01.15.33.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 15:33:22 -0700 (PDT) From: Kees Cook To: Vlastimil Babka Cc: Kees Cook , David Gow , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Rasmus Villemoes , Guenter Roeck , Andy Shevchenko , Paolo Abeni , Geert Uytterhoeven , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH 0/6] slab: Provide full coverage for __alloc_size attribute Date: Tue, 1 Nov 2022 15:33:08 -0700 Message-Id: <20221101222520.never.109-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1349; h=from:subject:message-id; bh=4rGBtaTvxIM2S2/tPru2D68sOkXB0OX8taEZHOLdk5A=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjYZ6paKyWzltjIhIG7H0wMcmkzTKNPFcf0RIsjPcQ vls+JumJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY2GeqQAKCRCJcvTf3G3AJmhaD/ 4lXpEd5+FSEkLBgnULLWUZaf/s6kJlkkyVtXxDxiohZtDko1Y9Yu0jvxNCapl+fgMWJsyBOYbL/5d2 iqO0XLVzGMc3Wy0jJy2o8POCopW0DuxqjTM9z9CLYyn6pMwxfR4QiybtO2tH9yHSB1SqrmKpgelEBH jlWY4WdZt1HbAq6wyHDBVI4NTdjwn5Xs5GgS72fBWIDTvU/uOGN9geVRMqtSTl9PjvhR0kbqOn7D25 xB9m4nxsVeFeTTwr59srXsuYsuJYiCemNooObZdDbWRg7/MvfHZ0Gn6Po6sfLGLiuiLg/N1UiQN6fr vrtMR34lGGmcZ3toePjh4MQHyOc+s8rKaV+BuqdRIY1WnRK8nvK9UonxkUcqGob7oIKFYnTJHDEDpf qJYd3ITuoSUySrEJWRwkNa/dG0wmrvIglpQintfD9RnQVBtjRxohxctq8FW4OAZBPZzNzHrOWtEwyS aT/7I0wSnAe7UZDWYdMcyqL9E08/LjpdrROOA9CcIVfm404TmVSLHf0k3SWwAeFit5m7dltTbMkB1l ixOhSpcykpLXjZX/hjXIgO6io8YXBIIutYlKqQ+tqmgIkWysbCniABDcKM/1kBiHLbZRtoUXdCFITI q7HqFyGHCAORZNT5JeGUETatf9l8xz5PKo7T8MobhoxhzcN8FIqIy00fThig== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667342004; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=x+sHrlQ9qvuRyCEzJ8tyDL/yT5sTtV33z7B4OVR3Ags=; b=xarVVX5uyWkZFxrzyJhFtIKv7PkCWV/bCksikmE/YUzEtT6D2TPEshQTgN7zkfbD/yuTq9 nZN0nGKT6+XNKdzAAJrYQNk28TRhQAhg/cSDhI466hMeFYGedOPmMPmxAYY0AwGic0SG+Z xLq6mA/9s+8lpRp2IFTtRVwrwjXOwqg= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=VWzODwGP; spf=pass (imf04.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.174 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667342004; a=rsa-sha256; cv=none; b=YzzKz0TXaqWNB3/fzoLmC9Jtmy4uq9QWzd77poMTET+OkF3FjOFlcuQzWRe4Y7Va+YuoA7 lRJ957VpAid4zn0n8iAtIbyZwX71lVOHUCUAlN867pFNdhnM1LR9SwBkULGCkCXr0K3p5N 4+E5cEeo6wacb/yyr+7SEo7EhI/xNG0= X-Stat-Signature: 393sg6orf146e1j91dz3g3j65bfc8568 X-Rspamd-Queue-Id: 1A91140006 X-Rspamd-Server: rspam06 X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=VWzODwGP; spf=pass (imf04.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.174 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-HE-Tag: 1667342003-278920 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi, This is a series to work around a deficiency in GCC (>=11) and Clang (<16) where the __alloc_size attribute does not apply to inlines. :( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96503 This manifests as reduced overflow detection coverage for many allocation sites under CONFIG_FORTIFY_SOURCE=y, where the allocation size was not actually being propagated to __builtin_dynamic_object_size(). In addition to working around the issue, expand use of __alloc_size (and __realloc_size) to more places and provide KUnit tests to validate all the covered allocator APIs. -Kees Kees Cook (6): slab: Clean up SLOB vs kmalloc() definition slab: Remove special-casing of const 0 size allocations slab: Provide functional __alloc_size() hints to kmalloc_trace*() string: Add __realloc_size hint to kmemdup() driver core: Add __alloc_size hint to devm allocators kunit/fortify: Validate __alloc_size attribute results include/linux/device.h | 7 +- include/linux/fortify-string.h | 2 +- include/linux/slab.h | 36 ++--- include/linux/string.h | 2 +- lib/Makefile | 1 + lib/fortify_kunit.c | 255 +++++++++++++++++++++++++++++++++ mm/slab_common.c | 14 ++ 7 files changed, 296 insertions(+), 21 deletions(-)