From patchwork Wed Sep 14 02:00:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12975483 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 7741EC54EE9 for ; Wed, 14 Sep 2022 02:00:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 098EB6B0071; Tue, 13 Sep 2022 22:00:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 048116B0073; Tue, 13 Sep 2022 22:00:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E54248D0001; Tue, 13 Sep 2022 22:00:13 -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 D93E46B0071 for ; Tue, 13 Sep 2022 22:00:13 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AF1A6140F43 for ; Wed, 14 Sep 2022 02:00:13 +0000 (UTC) X-FDA: 79909035906.16.5521E8D Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf21.hostedemail.com (Postfix) with ESMTP id 6CDAF1C00AF for ; Wed, 14 Sep 2022 02:00:13 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id j15-20020a056902020f00b006aea95548b0so9396129ybs.19 for ; Tue, 13 Sep 2022 19:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date; bh=p6qCghWQbcRewzTnBFceTKv/Y60AI2F5NEC8++qJ2MI=; b=FZxg7ZQVvBz9WmQks3L0S9UYycRMX6FNxeIoQWOixAv/JrYVUeom0YA+u4RqWdG96c UwdDLEZHnTU9I9fz0Z4OhTcqYz8IgZPUx6E7lVUPz12DOMT5Zcg2kV0JLqQRW/Cp6/qK X48Ieg6gkbDHfOqruPwUwzv/U/9v40R+iLCA+WAA6lhXI7bkNeyefyLGfffTwIcxRSCL wQ6N8BDNCkqqQGI3bgOhAVcQHeGXF0u6Q97uk9y2UnlTFRG+43WFmAJpo2znrD/CzVAQ hMun9nt9+jT4b7CdL/NtNJjSBK+19f/WqTZqzIlXWaWjGWXvHNqCFIFKmH/pwWgkPEbn A7OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date; bh=p6qCghWQbcRewzTnBFceTKv/Y60AI2F5NEC8++qJ2MI=; b=jyDURnIhR6xPP1ZLlktkGC6RRXDswES5JgXK7Xp6p3P70l93siVEphj1k+9YG3UOv9 k8hsEx5FDqCArb1wylCSnOtVJ82e5xWuJTk6hZpiI7KB2Y08Y9in8IjuBr01zl5zyIaV BmQEym7tqSkBJKh0OLKPRYphb04dE9ezjTsdOrYcO/8MGdnC/h+fmqeiXIVRfGZzs6Jp G7WKYBZEdH3uP75qpmTewzK+XeJtknXI4Ujun2JbYvjHWXv9IqHTCpewJTt1shvfn7se mDh4DDXoNKzuC5b4N9LE6rx6VubmiIUHuT/4TZtVu7O008mYmNXNWvScfZJM6KyvVgDe 4E7g== X-Gm-Message-State: ACgBeo1NiVK7qyfgAfl+m6o9mA8udvSbSf32R6CJi5r1onz8h1WM/nKn IcoW3ZbM7Vq8+dV1yR/cvib/jag= X-Google-Smtp-Source: AA6agR4W0NwqBv0embkoehNEbFKrl95x/EFmpO/GESuyJ3JThH+BHAW+2aaI7Tl4bgr20j3mzjFMNac= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:370d:f9c3:6198:7768]) (user=pcc job=sendgmr) by 2002:a25:2687:0:b0:6a8:e551:b9d8 with SMTP id m129-20020a252687000000b006a8e551b9d8mr29117452ybm.472.1663120812652; Tue, 13 Sep 2022 19:00:12 -0700 (PDT) Date: Tue, 13 Sep 2022 19:00:01 -0700 Message-Id: <20220914020001.2846018-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH] kasan: call kasan_malloc() from __kmalloc_*track_caller() From: Peter Collingbourne To: Andrey Konovalov , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrew Morton Cc: Peter Collingbourne , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663120813; a=rsa-sha256; cv=none; b=a3ZIhQ3PxwBfj3Z6+KwK3OFa5cHIOxY6tedj2Jt/gkKN6+YGD4v058JrgK0t+QjI9/qaZi aWZIAgzsG40pv/SDip0iMbDJmPdxH/S1SHyLhwRHoT/axhfskalZXG+9APzUWanGU6uZtK LTVMumlzVn4cbLnvkcnC6/53W3lPWc0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FZxg7ZQV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3rDUhYwMKCLsqddhpphmf.dpnmjovy-nnlwbdl.psh@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3rDUhYwMKCLsqddhpphmf.dpnmjovy-nnlwbdl.psh@flex--pcc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663120813; 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=p6qCghWQbcRewzTnBFceTKv/Y60AI2F5NEC8++qJ2MI=; b=EN8BiagOvLN8Q2emzyn5W6gcFbVvmiiIbKU9B0bMVPdM1coYc4bqazC26xeoKB6szJln5/ MkL4vPeShoDfAI2UHIoNpGn2yEtln0pzPJmrDRpDYWwcs4Xvo+uhFsV0MXhfNazi79IZMs +zwekv6p4GXLYflL/mPFtXyoIF2KD/k= Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=FZxg7ZQV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3rDUhYwMKCLsqddhpphmf.dpnmjovy-nnlwbdl.psh@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3rDUhYwMKCLsqddhpphmf.dpnmjovy-nnlwbdl.psh@flex--pcc.bounces.google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6CDAF1C00AF X-Stat-Signature: nhki1dkgwk8p67sbigdphzfwuzsesgju X-Rspam-User: X-HE-Tag: 1663120813-538618 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: We were failing to call kasan_malloc() from __kmalloc_*track_caller() which was causing us to sometimes fail to produce KASAN error reports for allocations made using e.g. devm_kcalloc(), as the KASAN poison was not being initialized. Fix it. Signed-off-by: Peter Collingbourne Cc: # 5.15 --- The same problem is being fixed upstream in: https://lore.kernel.org/all/20220817101826.236819-6-42.hyeyoo@gmail.com/ as part of a larger patch series, but this more targeted fix seems more suitable for the stable kernel. Hyeonggon, maybe you can add this patch to the start of your series and it can be picked up by the stable maintainers. mm/slub.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 862dbd9af4f5..875c569c5cbe 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4926,6 +4926,8 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller) /* Honor the call site pointer we received. */ trace_kmalloc(caller, ret, s, size, s->size, gfpflags); + ret = kasan_kmalloc(s, ret, size, gfpflags); + return ret; } EXPORT_SYMBOL(__kmalloc_track_caller); @@ -4957,6 +4959,8 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags, /* Honor the call site pointer we received. */ trace_kmalloc_node(caller, ret, s, size, s->size, gfpflags, node); + ret = kasan_kmalloc(s, ret, size, gfpflags); + return ret; } EXPORT_SYMBOL(__kmalloc_node_track_caller);