Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7368389rwn; Tue, 13 Sep 2022 19:39:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR6bEsiQDFG3LDyeIE26ehgykATCAgQEejfsvk8wRp7DVABCeC5mjQWIWVjsWAAcjA/rYYQL X-Received: by 2002:a05:6402:350a:b0:452:8c84:8b with SMTP id b10-20020a056402350a00b004528c84008bmr3026325edd.93.1663123178612; Tue, 13 Sep 2022 19:39:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663123178; cv=none; d=google.com; s=arc-20160816; b=t2V/HxY/espxWC/yvmDB8XY7y6Tm/MoOhquZpoPcNW8uwdCeNBtBCRvw3o9rgzgEXC qAz8o9jPICyzpRYT8iD/3G6RfujOrJ6NXzXrE/O020Lm364Bqi2PgKLrmAU01+oZDS4b zn9cMn9lI/PYuKUlMOg0tnb7MnEZ/lLJA6I6AtapirI1AmpIwDF4DekQHSO85nZOV8jR /hqz+Clv29SyRdV48xf5as0JwstU+OAsYpMZhFeWiTF1o6rXoOndjdGkPtDJLytXd6/b +j0xkiN4NGk00+Uye1XQ7VqnNvPk9QG1b6OvIcV/bVTZmUeM3SQQLlesGZcVOWjZMxvX 3tsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=p6qCghWQbcRewzTnBFceTKv/Y60AI2F5NEC8++qJ2MI=; b=UeX+vk8vPCiWnblYfpznWD7/yf2lpjxbPzP/+P4ka6lTexyJhxFBa5Pwfp4bfSsRqO xqcNmuHvRWJheuAwoi6ufUdqQtUw5j35GtNz0gjPyWJC1GKJQSS8r7Je6F9OFaPFFuqd /WAhWDLnTIT4jvzV1snbPH5OBWIbGL3a1923hOdMk7Kpsm16GGP+fegkb94r9phudPgG 48dxncJaezehDOWCtxT3H/vjAWFbE2wfTKhxA/T1oDDgtEPFgpiQIUTojqDnUQuYDZLO x5/U8uXBT+HHKWUDGu5hbSoK1zuYehgVoHMHeyGvsv8fpbONtHoBSYgJoyPJAAeZKkH4 72YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FZxg7ZQV; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a0564020e0800b00452154c138dsi4539850edh.330.2022.09.13.19.39.11; Tue, 13 Sep 2022 19:39:38 -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=@google.com header.s=20210112 header.b=FZxg7ZQV; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbiINCAW (ORCPT + 99 others); Tue, 13 Sep 2022 22:00:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbiINCAT (ORCPT ); Tue, 13 Sep 2022 22:00:19 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EC2B3123D for ; Tue, 13 Sep 2022 19:00:13 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3496e668a5dso49910607b3.5 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=iCHTBKRPtXPy3vjDOjdxuTqLTVKPORQfQy9Kvmy6xG5Y1gmMYOCxwWifXIqIGPs5iY NINYIUuWDpqm3JVey96B71cULBSK70PSRVGcQxE6dMC7Zj+CeoIL12HpIFLH/1mUsrRo DFjUl3LEoLE0fyklPBRv4P9KdhmagD5hN5KGljyNQ5xxsuD2LxzTzmKWup7qEbWz78vn ZzokVGpZuaiG27J9CVN6qeTfscannoPcXp6vb0t2cw0tFJZBs8k0o6mlRPDLblgl8kT5 bcftung/0L4djKaWxRv5e0ErIBp0sDeRqvAjzhqMraAgBul0NuJIpFdh2q0acvLBBPeE P0xA== X-Gm-Message-State: ACgBeo3yL6hzcc4F2fygKlylDYPWf7clxSIT1MrftTComrQbOtqIFmbh UZLMeA/jyt2i646ALWYsyoAS4Lg= 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 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); -- 2.37.2.789.g6183377224-goog