Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1583415iob; Thu, 5 May 2022 04:36:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6EeR7zKDuqY3lIFz+Zi/7TNkUADo++SbYD5ku/C6VrGPVXgDv4B6GRHOidF/UthzWysnB X-Received: by 2002:a05:6a00:4091:b0:510:71b1:963e with SMTP id bw17-20020a056a00409100b0051071b1963emr612903pfb.31.1651750604634; Thu, 05 May 2022 04:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651750604; cv=none; d=google.com; s=arc-20160816; b=qymhrJzFPkIl3cyksooOAruC1DeQ/9+K+118Fye9KNnKuys/BomYmJNCnzNOkSgVBo NjJEt2fPVYZYFFp8dgJsqYC1DNsO94uUhz8ryWQ5V7NCov00R+sfsAsHLeKU2x/mMYQW JJOVrhCaHSjLNLrbvVTgmIhDjwwq5RB89qx/etMjkpLeju/qqcudeCNAQrX3XtYfENt/ cdPx6UFHZuD9bcJiT/qP4X8PRRinXmyzdvl6/SMdT/vvqnVv0HMeQGdEvrfTzPXK1OM2 mSINQohRV/KOjfTWKqcOjR3OTg8tIiGUbgpYS5CQwXbPAuniyTuhkr194tyl/DwonOaX YH8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=l9tcNjUdyo4TQZZgpUJnhpJabGIVu+DBpwHHuQmrlJ0=; b=KeHMAZA7OqkYz28pz2wr+TlmwpFhAXhUCLBjfOLMy7ZKXgc/1OG8DpJ9OKgHkgZm/r +YRQkNxuAbcJjfRQ3RK7eiRZMP3XzoV36upY7oqNfoksK7YiXdXAXBtiRj8+dgRTlf5e E9tjmId49mkAyXQ7IC56nb+bedabLm2IqwQoKsuO02MIwCaUDmQOF6gouTkr4qhTSOYI 44ejKgnUNcV6p9qJr6OSe7dzHNPqG+oaw67pKK/4thGoWqx4/qqxgXR4AoEi9wfUuh+r vhYpfE7HwQeCAE8gI3/Ir7Ws/JeuT3ItRBFus/lmGEP5UcSHn8JZ/J6IXjOCWvKv4Ldv Ml7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=coNhCWYq; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 200-20020a6306d1000000b003ab5908dc1csi1404591pgg.22.2022.05.05.04.36.29; Thu, 05 May 2022 04:36:44 -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=@linuxfoundation.org header.s=korg header.b=coNhCWYq; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357693AbiEDR3K (ORCPT + 99 others); Wed, 4 May 2022 13:29:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356263AbiEDRJI (ORCPT ); Wed, 4 May 2022 13:09:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB989532C7; Wed, 4 May 2022 09:55:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 62499B82552; Wed, 4 May 2022 16:55:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07A30C385AA; Wed, 4 May 2022 16:55:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683300; bh=LqikQVruDlTPY4W8yio5ZihTYRkdGJY8fqc90o2rNZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=coNhCWYqnrfqNT70riuu9EaJMYjXCRe8MoUHkS4QnwZsN2SnQX+PeZ22BtIL+yjRR hYuE0lieZwFOJXdjWtThiQP2bKcZ9ptU2KuN2tjs6f5wk3Wukm4Dkix3wi8dumLoui v/sJjhOYMMZ2c/fRoZvgW8ZE9bVKpU8eT582Kpmo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zqiang , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Andrew Morton , Linus Torvalds Subject: [PATCH 5.15 143/177] kasan: prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time Date: Wed, 4 May 2022 18:45:36 +0200 Message-Id: <20220504153106.070173619@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Zqiang commit 31fa985b4196f8a66f027672e9bf2b81fea0417c upstream. kasan_quarantine_remove_cache() is called in kmem_cache_shrink()/ destroy(). The kasan_quarantine_remove_cache() call is protected by cpuslock in kmem_cache_destroy() to ensure serialization with kasan_cpu_offline(). However the kasan_quarantine_remove_cache() call is not protected by cpuslock in kmem_cache_shrink(). When a CPU is going offline and cache shrink occurs at same time, the cpu_quarantine may be corrupted by interrupt (per_cpu_remove_cache operation). So add a cpu_quarantine offline flags check in per_cpu_remove_cache(). [akpm@linux-foundation.org: add comment, per Zqiang] Link: https://lkml.kernel.org/r/20220414025925.2423818-1-qiang1.zhang@intel.com Signed-off-by: Zqiang Reviewed-by: Dmitry Vyukov Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/kasan/quarantine.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -315,6 +315,13 @@ static void per_cpu_remove_cache(void *a struct qlist_head *q; q = this_cpu_ptr(&cpu_quarantine); + /* + * Ensure the ordering between the writing to q->offline and + * per_cpu_remove_cache. Prevent cpu_quarantine from being corrupted + * by interrupt. + */ + if (READ_ONCE(q->offline)) + return; qlist_move_cache(q, &to_free, cache); qlist_free_all(&to_free, cache); }