Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp875452rwb; Thu, 6 Oct 2022 05:48:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CTQHUWwrd/XQI4jaNxKVbyj3NlZq813lGmIQisS78ItiM8h6nr66xK65Y0Bdh4LIOaZxW X-Received: by 2002:a05:6402:11cd:b0:452:199e:7cf6 with SMTP id j13-20020a05640211cd00b00452199e7cf6mr4571779edw.366.1665060501669; Thu, 06 Oct 2022 05:48:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665060501; cv=none; d=google.com; s=arc-20160816; b=B01gI8m4wdl3EUVaKiAjEtWahZbF60YE0CgJ4tHh8s8CWYJA7np+SeUg/J5JJ+8QFc me6gcG3npHNIFupJLmQstLizLz47wKjkBBLvz/awJquEhAc2jlcKttw69D0e5x7RhQEM zesEKmykK2UH5jYIAIjz9FNC9mKAjr9UF1d2aeDFeiWXJ7rlLuMkfqdKmzXbvqh56YiV zl7AF/iuXS+ww+BKAmeLEUg0ZLEYLrk9rRr08vzPRBe7lBygvnzBMNYKdu0Hsq8kalVH CUoMFuNCqTQotZS7Kr/84qa16G1YPX2p+Fl4wgOMGWzY0Hw6J3RCC2hFuP8hFbrUbP75 c3wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=6MMPcKf9F1/2/vMYQPdhouNSSpWXHJ8lbaTT/pcZEL8=; b=Mny70SnuqVRBp8AHZzZksz9eNKnATBDKVR5SPjb5LAosR8XMFGqPxDjI/oAPe3yH3O Umt//dd7Gm6k0spuV/hvxt3SOir7Vctf5/rt+treb9v5QbmwErzAGIAGCPUBLxjsZ0Mo 6dFYvsis51bL9XUKFBizCJjZTF5ma0N+CWkSdQtsClaO3SoTu6iK3ntxRMLanKvIC0xm oSPTuvhwmEHYUIshfjgNyhWAu1DpYsKSl/NbHgkjcB6UUI3kFxEWnJh0pNfGEXoIABzU peWMXk+xpFLK4me9NgUcAN1PThz8QaiVgjpnDL22nDLhZz8Q3ZjxJ/wuierMWekv6siG oC4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=B4jDCZe4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=0131keFl; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs38-20020a1709072d2600b0078266dc4b8csi18600311ejc.719.2022.10.06.05.47.51; Thu, 06 Oct 2022 05:48:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=@linutronix.de header.s=2020 header.b=B4jDCZe4; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=0131keFl; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231452AbiJFMl3 (ORCPT + 99 others); Thu, 6 Oct 2022 08:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231200AbiJFMlV (ORCPT ); Thu, 6 Oct 2022 08:41:21 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 791488E9B8; Thu, 6 Oct 2022 05:41:15 -0700 (PDT) Date: Thu, 6 Oct 2022 14:41:11 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1665060073; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6MMPcKf9F1/2/vMYQPdhouNSSpWXHJ8lbaTT/pcZEL8=; b=B4jDCZe45EMiTYcRwUxKpJFXs+GVJcNEfl3cK+Vqnv3flta+Ciey7tUEaVX98drlabNwGt s2R0wIGEg9qvqDK5maqph1ChgESQ4yCCRBWE9r5GWBjxlrPVYFlJPwHQnL60p3xYzG/HcQ JaGfSs39F4kxKiTc8tXw160j56br2f8q9+zHRsLFEQ4ROh9EVsdGRWYuKsRfqQcXR8R6nF MnaQKGmg3GMGQ35QeRxmtzvs7TtY9jsxo76b3osu/KEzB0kd5uNu44CI2HPoNqE80oZyJ1 ZhDQAt641axip/h4GBwlYTeichbuXW5gZsLXYlRXZlIk59eeHtJkRw42pugkYg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1665060073; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=6MMPcKf9F1/2/vMYQPdhouNSSpWXHJ8lbaTT/pcZEL8=; b=0131keFlC/RIBFVE8ywl48xXejRD4/fVEA0gq9uJVZELDvY2AfHZa5t/1mfSHgAfWZGeoC epMyZYPAHK5Vs0Bg== From: Sebastian Andrzej Siewior To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Dominik Brodowski , Sultan Alsawaf Subject: Re: [PATCH 2/2] random: spread out jitter callback to different CPUs Message-ID: References: <20220930231050.749824-1-Jason@zx2c4.com> <20220930231050.749824-2-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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-crypto@vger.kernel.org On 2022-10-06 06:26:04 [-0600], Jason A. Donenfeld wrote: > e) del_timer_sync() on line 5 is called, and its `base->running_timer != > timer` check is false, because of step (c). If `base->running_timer != timer` then the timer ('s callback) is not currently active/ running. Therefore it can be removed from the timer bucket (in case it is pending in the future). If `base->running_timer == timer` then the timer ('s callback) is currently active. del_timer_sync() will loop in cpu_relax() until the callback finished. And then try again. > f) `stack.timer` gets freed / goes out of scope. > > g) The callback scheduled from step (b) runs, and we have a UaF. > > That's, anyway, what I understand Sultan to have pointed out to me. In > looking at this closely, though, to write this email, I noticed that > add_timer_on() does set TIMER_MIGRATING, which lock_timer_base() spins > on. So actually, maybe this scenario should be accounted for? Sultan, do > you care to comment here? During TIMER_MIGRATING the del_timer_sync() caller will spin until the condition is over. So it can remove the timer from the right bucket and check if it is active vs the right bucket. > Jason Sebastian