From patchwork Mon Mar 6 11:13:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13160983 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 BD28FC678D4 for ; Mon, 6 Mar 2023 11:13:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EAD26B0078; Mon, 6 Mar 2023 06:13:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 57382280002; Mon, 6 Mar 2023 06:13:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 413B56B007D; Mon, 6 Mar 2023 06:13:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2FF606B0078 for ; Mon, 6 Mar 2023 06:13:30 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 05B40C0BF7 for ; Mon, 6 Mar 2023 11:13:30 +0000 (UTC) X-FDA: 80538212580.17.14B682A Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf21.hostedemail.com (Postfix) with ESMTP id 33BD91C0007 for ; Mon, 6 Mar 2023 11:13:27 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GQwsOOCw; spf=pass (imf21.hostedemail.com: domain of 31soFZAYKCKkPURMNaPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=31soFZAYKCKkPURMNaPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678101208; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=1YDcalZhdE7jkjuSChjdb8BwAiaOVabLcoERtRrllCw=; b=LBBNKz2HzUyXaNvhzFuMIX2dn6rLi3R8swazN0TDcGCecCJ1/JqK38cCJ1KAkuyFIJEsoW kChO+rA+2uuElrRQeoepRE2hzWsmcrODsi7Xfn8qK9/ffDmDJqbjbP2tISd3/jzki34awS 1yL7L0/z4yt/Z0aXXL45JJgCYR4MmWs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GQwsOOCw; spf=pass (imf21.hostedemail.com: domain of 31soFZAYKCKkPURMNaPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=31soFZAYKCKkPURMNaPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678101208; a=rsa-sha256; cv=none; b=D6Y0RgPqNPOBgFOAoZETSIrKpEF7dCDj6AqaX3wB1vHVATydmzMdQ7hw5lqjXdz1GX8NfZ JTOmQyRNREou1ZBH07LB9Xw8lGBGmrp3hDCZBxgtfWIXFxtyFqzS9DHSfI7G+WlnaJwhrX YQczocoP9gqst+M7ha+c2mXqv+AgpPc= Received: by mail-ed1-f73.google.com with SMTP id g2-20020a056402320200b004e98d45ee7dso1546616eda.0 for ; Mon, 06 Mar 2023 03:13:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678101206; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=1YDcalZhdE7jkjuSChjdb8BwAiaOVabLcoERtRrllCw=; b=GQwsOOCwt1r07r7xKoYaCxR+u6XnS4orZ/5XRefQQxUFaCbyY2q5e5ZsvfxrpiDk9b SrwfsLoY5AOl6cH4+pIVBvvhMqLtXqfcy8LnJd9LtbA2puKgHz3XhwV1m7uKOrmoNcNZ hlyU8r2pyRGzu9SodZfYSbjLIs3eumpGUHxxGs8nswjvWh3ypHGXOhXmf3Z5y6t1yOHB PTUpGiRLo6SLlJ2eRtuMJJ71s3LG+L1Kf4lQq8GLOrUWsBFN7Z2GeK1vc6pd+PR5FSOz of5RXfO0kfqI0FEwSmJNakpzkIV4EY5XB1gC9vzImzS4WsgaqVPUR1M2jpo5c9uPmEJv OH/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678101206; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1YDcalZhdE7jkjuSChjdb8BwAiaOVabLcoERtRrllCw=; b=cwpCeigLS6P2fMHNR1M829AQI6yJWGZI/o8JrRohN+/cIbhh2aKhOchzMUvCg3SQnd 4iVOxKmb5pgNoWWrmrnpktWcXuKyaoqqKvZUhksG5IsMFvv3LUTuLeW0Xd+nORIUMiur xIUCzgUunsq7Gdeqmb9DYxyRZomgbBT4c55U/NwnKBz1NO5qJHIbdPUsMGQrrMaMH1cL idpBXAAJaqLwKyRBTqBJvqm7n45Kj+3ZxFQi4fUKa0VsanCaE6nodzLeslUeUjITqr0P E0LtDYxmMdo6hy+EZs8pTQiQjLbxltpIfdEtbJa4dGis0bsvFJz3ncHHAmci6bDebXim rlIQ== X-Gm-Message-State: AO0yUKVb7yOFycgbDw/5hvkRm+Bj4HgeAnXjRyYwdI/GgF/xIPROY4cz EqLlFgrVpwQFoUg3DocqFfX0kanImAM= X-Google-Smtp-Source: AK7set/52SkcXdTHtfRNAJvdgql1aIbZ/I0TQcEPsji0Ir0BgvHo9ob16KHkabtruxTJf8Mfuwju3r4XkNQ= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:b93a:5d85:6f2c:517d]) (user=glider job=sendgmr) by 2002:a17:906:ce38:b0:8b1:30da:b585 with SMTP id sd24-20020a170906ce3800b008b130dab585mr4991214ejb.6.1678101206445; Mon, 06 Mar 2023 03:13:26 -0800 (PST) Date: Mon, 6 Mar 2023 12:13:21 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Message-ID: <20230306111322.205724-1-glider@google.com> Subject: [PATCH 1/2] lib/stackdepot: kmsan: mark API outputs as initialized From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, elver@google.com, dvyukov@google.com, kasan-dev@googlegroups.com, Andrey Konovalov X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 33BD91C0007 X-Stat-Signature: 86rbhb67xqnncai5pq3ouwfke6tzrmo9 X-Rspam-User: X-HE-Tag: 1678101207-312116 X-HE-Meta: U2FsdGVkX1/vdOm4XXuNZkeMtzJo7Xi7bP5BDy3L7vRc4EBRnMUDu+b+tCan3FX+0ciTLJaOjMiOU1/Q8fnCjRBfnHrH7H1mx+Seys2H/q6Xb0SXYZbKuuBO5boogAp/e11boDNR/YnABK2cMyyfYa8JenAacobSjyxDAuA1psMVqshk5MsBZ8F9gE0C5rMqLE7oBtRdF41YjDFhjfdLUE3d/GmFGcVCUsALVBQfA9tg7PYgJe+7BlYWRFodnkPoCCPzsFX+BzVUCd/jSioWHjy4CWF9V+9TZI+5owkShuk7lGn4VCrUsKArrArs2yd35ChQG32QFd6u2nXWPPopzWCWIr2uFwOyHGTtcr29kIl3RKX+Gtk6uVZe3AC2D+3qfbwNASolKSXiPnTZ4nFceEyrnR3OV3oY70iB4K8y6jfaTIeLmE/+0EWkEKA31PHCBRHIUSXPobDI7E3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QFsGXcA4exhKNQY7aB6z0QGjix8sTFxCJkIUS5AG3aMF6K4C3ez3ipEEdOpuOQsX1N1v3fz4ify0+vfL8K6oKP6Y= 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: KMSAN does not instrument stackdepot and may treat memory allocated by it as uninitialized. This is not a problem for KMSAN itself, because its functions calling stackdepot API are also not instrumented. But other kernel features (e.g. netdev tracker) may access stack depot from instrumented code, which will lead to false positives, unless we explicitly mark stackdepot outputs as initialized. Cc: Andrey Konovalov Cc: Marco Elver Suggested-by: Dmitry Vyukov Signed-off-by: Alexander Potapenko Reported-by: syzbot Reviewed-by: Dmitry Vyukov Reviewed-by: Andrey Konovalov --- lib/stackdepot.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 036da8e295d19..2f5aa851834eb 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -306,6 +307,11 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) stack->handle.extra = 0; memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); pool_offset += required_size; + /* + * Let KMSAN know the stored stack record is initialized. This shall + * prevent false positive reports if instrumented code accesses it. + */ + kmsan_unpoison_memory(stack, required_size); return stack; } @@ -465,6 +471,12 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, struct stack_record *stack; *entries = NULL; + /* + * Let KMSAN know *entries is initialized. This shall prevent false + * positive reports if instrumented code accesses it. + */ + kmsan_unpoison_memory(entries, sizeof(*entries)); + if (!handle) return 0;