Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp853640rwb; Thu, 6 Oct 2022 05:31:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5r9ELzj+syW58LCWh/1uWewGTbh6HeW45d7H3XsUiaKqqvXmrIz7hI6c7KRZfrq+241D3I X-Received: by 2002:a17:906:c14f:b0:78d:105b:e57f with SMTP id dp15-20020a170906c14f00b0078d105be57fmr3829666ejc.672.1665059472455; Thu, 06 Oct 2022 05:31:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665059472; cv=none; d=google.com; s=arc-20160816; b=ihOIq/V4tWp3y6tnmniScP+C8fel0vlFl19BKvzIDMKSe7Qck+vgcgItK/I+GhGCqa y2FXV+0Zsl4i6C7wDXyoOO8QXlFYLtOdnkWxgqX7xF9bn3lb0guHy+tIWBitWsDJat85 YIrFhy121+so+mO8aPFksW8otCKvr3NTxqN+Lzp80XSx+L+eZUxDolK9cAFW8B9RJgTy ND8srpbKgM7w5EP2qHkJlmJThLbfXUgwnlaJLOk9nHKFUR1mwqSc75+UkzyxsGP9M8zP H+cJNfayfFEjh9BC5ol9YAN/UEZKPN/FPOgkyCbdqyWGClUl6L1ou0YCPdksniq7B2lJ +rfQ== 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:date:dkim-signature; bh=6iPbXN5uNEWV3YZEUMKktzYcuhWOhctZeQ02euetF3U=; b=DYyMUkJeiz4wBuRBXWTcGugz5w6TgvL5CcxVTvhohnS3JOIu8bRRqLUSbdANDsuefO JgbctQbv9/AS6G3o4OlErL3KwI9VEIklDzHeFUIkg1k7Dhwti6aa0KtTU/w73OSb6K6+ rYETS3OypQQ0qlWn9YhPiTarDPPznpw8mVixo8f5bchDZwcQUr8OooD6Vd+wNi8CG6Bl MN0pUwrSxwL2BbzMWMgmZj2JmYZLB1q98Ky/yqCEQDwKnGlIpU8P22PuWkQeOpUBiVMO SBlLrUOluUQXtmaFmxydmnxty7I6fyDKbe0MI6OqV9B+4jKhZlmtCMfZJf7NExXENgpj BwOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=TsTm67Ll; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b16-20020aa7cd10000000b0045921e99f8csi8579070edw.182.2022.10.06.05.30.45; Thu, 06 Oct 2022 05:31:12 -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=@zx2c4.com header.s=20210105 header.b=TsTm67Ll; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbiJFM0N (ORCPT + 99 others); Thu, 6 Oct 2022 08:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiJFM0M (ORCPT ); Thu, 6 Oct 2022 08:26:12 -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 DF3DA7679; Thu, 6 Oct 2022 05:26:10 -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 94AE2B81A76; Thu, 6 Oct 2022 12:26:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2444C433D7; Thu, 6 Oct 2022 12:26:07 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="TsTm67Ll" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1665059166; 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=6iPbXN5uNEWV3YZEUMKktzYcuhWOhctZeQ02euetF3U=; b=TsTm67LlKD3Gjx0PkIPYMdh+9AE8HCA9QwFABcH6wyYNxUdbzfLcKHnWSK9lhDBErZJmos TCnYP4JIuDGVr3slI2hykp9bmVEX2jhkw3DUVyqEFLkbgaf2uDc97s0J4Jpj3NmnMbmXmX vwh/HpR0E/moBel5/P+VZgtJsON2D2A= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 8808a601 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 6 Oct 2022 12:26:05 +0000 (UTC) Date: Thu, 6 Oct 2022 06:26:04 -0600 From: "Jason A. Donenfeld" To: Sebastian Andrzej Siewior 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=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,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 Thu, Oct 06, 2022 at 08:46:27AM +0200, Sebastian Andrzej Siewior wrote: > On 2022-10-05 23:08:19 [+0200], Jason A. Donenfeld wrote: > > Hi Sebastian, > Hi Jason, > > > On Wed, Oct 05, 2022 at 07:26:42PM +0200, Sebastian Andrzej Siewior wrote: > > > That del_timer_sync() at the end is what you want. If the timer is > > > pending (as in enqueued in the timer wheel) then it will be removed > > > before it is invoked. If the timer's callback is invoked then it will > > > spin until the callback is done. > > > > del_timer_sync() is not guaranteed to succeed with add_timer_on() being > > used in conjunction with timer_pending() though. That's why I've > > abandoned this. > > But why? The timer is added to a timer-base on a different CPU. Should > work. So it's easier to talk about, I'll number a few lines: 1 while (conditions) { 2 if (!timer_pending(&stack.timer)) 3 add_timer_on(&stack.timer, some_next_cpu); 4 } 5 del_timer_sync(&stack.timer); Then, steps to cause UaF: a) add_timer_on() on line 3 is called from CPU 1 and pends the timer on CPU 2. b) Just before the timer callback runs, not after, timer_pending() is made false, so the condition on line 2 holds true again. c) add_timer_on() on line 3 is called from CPU 1 and pends the timer on CPU 3. d) The conditions on line 1 are made false, and the loop breaks. e) del_timer_sync() on line 5 is called, and its `base->running_timer != timer` check is false, because of step (c). 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? Jason