Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1689255iob; Thu, 5 May 2022 06:32:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqoFLXsKZvabBQWv9eysMkdSYCRQvphDXEd35+BtVLcOG76i4ud1kwZUX9tpmFJIqEIrw9 X-Received: by 2002:a05:6402:1297:b0:428:3848:a89d with SMTP id w23-20020a056402129700b004283848a89dmr3531726edv.94.1651757578686; Thu, 05 May 2022 06:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651757578; cv=none; d=google.com; s=arc-20160816; b=ubKjIzl8+pVexiRbe9+MIvqPimVX72Rq+BmfpelQrG0zo+JZqZW8WXpm9DNh+eqMu1 EWeMgnrWiklkDoYec60QjHjIvD85XTAaaKOY0ixmpfvQ2C2VDxkuD1caPy8sgIOa8rA8 rlyu/YOJL+qCSisokEqermoh/ULAtmjoRMD5bE2y4JpYt3XALQ6h5DofZh/l+kZO1/BK QqQ3ClXS+kTjFwc7hZbmP2CjhBW0vGstyzR1PK4SKGCgF+l5p3CtvM8q3t8PBqhdMIqQ RPkwKuNdh1QDu4wGU9KXaQb/YMfBko6Lpbkf+9DZJ2Y9LIE9LYH8Y6Fmfblja3YBVi6I orsw== 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=pfqMSdzv6DX5QyfuLOTfI+Fs7ffzgaWtzyi7B4DvEt2ZkonKS6BNGxRWBsfnSWUEPo wuDdyAwBRArvr00A/B/V6SxMZrekAYmrR4FUuVvvxopsbeOWTS139I9q1RFFFFLSO7FE SI+/NxS9LEiqdWu4WTzpyT2KL0eKVSry4t/bxcRuZpgor8OfWbpVkjksa2V67jG3bIR7 GCDr5qOveug7vave6uQbbs8ffYsWWYo03EIY01tncKrSUlgntIUDwTrvittK+kmRuTHv FbQpK3QYPmxauswIYjXx12IadiPPV2Eh4nyb5KK2HTyEM/35Ddc26kplTTMxjrUAX3Xm liTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uNc8ULna; 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 i1-20020a05640242c100b0041df73164e1si2294512edc.508.2022.05.05.06.32.34; Thu, 05 May 2022 06:32:58 -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=uNc8ULna; 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 S1359181AbiEDRsd (ORCPT + 99 others); Wed, 4 May 2022 13:48:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357329AbiEDRO7 (ORCPT ); Wed, 4 May 2022 13:14:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79287541AC; Wed, 4 May 2022 09:58:28 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 3CEEE617D5; Wed, 4 May 2022 16:58:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C2DAC385A4; Wed, 4 May 2022 16:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683507; bh=LqikQVruDlTPY4W8yio5ZihTYRkdGJY8fqc90o2rNZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uNc8ULnaN9rkQig+4xwoqdJPIm8Aw1v5/Nx5+11OIKgslFKeHbNIuWpAE+HoDbkVr 3W1L81CN0X6uNjwu+e/K5j/6hffU3iB1dp22CRBetRR7bTjFiXNHPGBt+EcbChDmgG z93SqBH66D4LFl/FEZ4YKjKe9u8ukUkaiiOYwHfs= 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.17 182/225] kasan: prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time Date: Wed, 4 May 2022 18:47:00 +0200 Message-Id: <20220504153126.695302662@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153110.096069935@linuxfoundation.org> References: <20220504153110.096069935@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); }