Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1042979pxm; Wed, 23 Feb 2022 16:40:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9TFQtgcUths7e8GcSh281r01i1veMiakYD4lYotyk163DBKruzcgelXxKApuOWOp9hTGo X-Received: by 2002:a63:ce44:0:b0:36c:d02:1f52 with SMTP id r4-20020a63ce44000000b0036c0d021f52mr310551pgi.142.1645663213685; Wed, 23 Feb 2022 16:40:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645663213; cv=none; d=google.com; s=arc-20160816; b=BtgWfLeriNav44ocED6ZkJIPHR6MuOGNqQrOCe7UVsYVT5+JPkwFtYmLJlrXez1DmG P/GCMPUxaxod9tA6fuyadQlejMYUeS6XE+FkwHsUT+c8N9umVazQlILv41MGwscn6bfW oDa0/Hi49ORE7Yz8hUWMwRj1wyA2NIARSVQKgZRewQ9mB7ekeFbf5Ua+nRZ4/MJzyM5L ub1m30mBJTbQNMCeTAlj1a9IaRlMk7NQFbdRz0wEuhaV0v5oNkPT0xuv1Ozu7GeWbf+O OX+IdkAgWC5lqHSZVIia/aeYi91jZOEwg4/vP2t1RceXvA8FV14O2pBjA08tvQ2tJhSF CPUg== 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=rcZtDDDiBwFJfxUmlCOz3RDMEXHNKOOpzN1iEr3gL5U=; b=Mo4d+NyYCLahpA3At6qHmu7t83uhdjkdnj7NI110r22eXCUMSzX9Q5Na07p2BT6T9f 2C/W6IJ+3r9tRRiD2/6BbumSnEn+5YCQTLuWChimDq12Be/d/BQPVjlRO1anpqox6INg kz/zdptqHLq/y4UJxQ+3D2U0qGMslPEzvjx+kLt3ykgO1hBhTz73VDxR9dfiBN9wbyCT OqRDzZThUd0yr0xIeV3Zz/PlQaG4WK2hIbzx2z/xtX1OwDjmxt/xAp9Mmu0p4rNgLUBl CCyy18GU5tsQhG0D586fLskpCz0HJGlmc3I7+9U9YwdVh0OSWk7tJ3cUv+n8NzN0e9c5 pFDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QWBzyrjZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m25si1152153pgv.794.2022.02.23.16.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 16:40:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QWBzyrjZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5D63D9EB92; Wed, 23 Feb 2022 16:38:08 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239342AbiBWTaO (ORCPT + 99 others); Wed, 23 Feb 2022 14:30:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238408AbiBWTaN (ORCPT ); Wed, 23 Feb 2022 14:30:13 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14BF147AE4 for ; Wed, 23 Feb 2022 11:29:45 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id q8-20020a17090a178800b001bc299b8de1so3958859pja.1 for ; Wed, 23 Feb 2022 11:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=rcZtDDDiBwFJfxUmlCOz3RDMEXHNKOOpzN1iEr3gL5U=; b=QWBzyrjZbDyYSLOvasncoWEYru0Moni/yVGRO01JjZbgsx9D2Olu/maNAtD0effRNG wNYTVyenRE2iN8/gxF8zvDFIp1czImRucV3q+rH/Db4mDxfkNsMa5DdPNA12q8f3hQw0 CGhSrzqNOX9eTGM8sUUHgDxFqNl+jJQdeU/Ko= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=rcZtDDDiBwFJfxUmlCOz3RDMEXHNKOOpzN1iEr3gL5U=; b=BIc/egrS7GoaMYUXhvfghSZ7EX4sjwFPwZpXEhVqipTeDFHKI2Dmh1NsUYenLQnwzE qMJk7i7FJLHxq1ei66+zGmBZfBu0y44wDplEARJRkHd36pJsaf0nj3HKHPEYSh5Njh27 QP80dvafqo+6/5HdCdmeZBglLGjDyEPbe3FprKlmcFSuyFUfeeh8wADCi955wAoxVVK7 enlVS6d9avjP52iTnksHmR+16FEugMkqv8Tk8tUx3DPBui2j7LjwvPIisnfje91Y5vRo PlkDDq9S/0hpI0b+5bbJkRBxoNNPGao/9AU5Wr9xa5DolIimQiSFL5IqKMNa3NcxCHON J8Pg== X-Gm-Message-State: AOAM5300+Us7kwjqsFTKaGoUJTG+4zPX6KMpt5DGoFRyaXxVBXGXopnK fc8VKe1lzxZvlOOUcrdGs87k05xwa6FkVQ== X-Received: by 2002:a17:902:ab12:b0:14f:ce60:2ae4 with SMTP id ik18-20020a170902ab1200b0014fce602ae4mr1048141plb.87.1645644584562; Wed, 23 Feb 2022 11:29:44 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id on17sm246496pjb.40.2022.02.23.11.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:29:44 -0800 (PST) Date: Wed, 23 Feb 2022 11:29:43 -0800 From: Kees Cook To: Jann Horn Cc: Anton Vorontsov , Colin Cross , Tony Luck , Ard Biesheuvel , Sebastian Andrzej Siewior , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] pstore: Don't use semaphores in always-atomic-context code Message-ID: <202202231128.E7445769AD@keescook> References: <20220218181950.1438236-1-jannh@google.com> <8D85619E-99BD-4DB5-BDDB-A205B057C910@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Wed, Feb 23, 2022 at 06:50:52PM +0100, Jann Horn wrote: > On Wed, Feb 23, 2022 at 8:50 AM Kees Cook wrote: > > On February 18, 2022 10:19:50 AM PST, Jann Horn wrote: > > >pstore_dump() is *always* invoked in atomic context (nowadays in an RCU > > >read-side critical section, before that under a spinlock). > > >It doesn't make sense to try to use semaphores here. > > > > Ah, very nice. Thanks for the analysis! > > > > >[...] > > >-static bool pstore_cannot_wait(enum kmsg_dump_reason reason) > > >+bool pstore_cannot_block_path(enum kmsg_dump_reason reason) > > > > Why the rename, > > That's one of the parts of commit ea84b580b955 that I included in the > revert. "wait" in the name is not accurate, since "wait" in the kernel > normally refers to scheduling away until some condition is fulfilled. > (Though I guess "block" also isn't the best name either... idk.) The > place where we might want to have different behavior depending on > whether we're handling a kernel crash are spinlocks; during a kernel > crash, we shouldn't deadlock on them, but otherwise, AFAIK it's fine > to block on them. Gotcha. I'm find to avoid "wait"; I was just curious why it was changing, but I see now. > > > extern, and EXPORT? This appears to still only have the same single caller? > > Also part of the revert. I figured it might make sense to also revert > that part because: > > With this commit applied, the EFI code will always take the "nonblock" > path for now, but that's kinda suboptimal; on some platforms the > "blocking" path uses a semaphore, so we really can't take that, but on > x86 it uses a spinlock, which we could block on if we're not oopsing. > We could avoid needlessly losing non-crash dmesg dumps there; I don't > know whether we care about that though. > > So I figured that we might want to start adding new callers to this > later on. But if you want, I'll remove that part of the revert and > resend? Yeah, let's just keep this static -- there's no reason to export it. > > > > [...] > > >- pr_err("dump skipped in %s path: may corrupt error record\n", > > >- in_nmi() ? "NMI" : why); > > >- return; > > >- } > > >- if (down_interruptible(&psinfo->buf_lock)) { > > >- pr_err("could not grab semaphore?!\n"); > > >+ if (pstore_cannot_block_path(reason)) { > > >+ if (!spin_trylock_irqsave(&psinfo->buf_lock, flags)) { > > >+ pr_err("dump skipped in %s path because of concurrent dump\n" > > >+ , in_nmi() ? "NMI" : why); > > > > The pr_err had the comma following the format string moved, > > Ah, whoops, that was also part of the revert, but I guess I should > have left that part out... > > > and the note about corruption removed. Is that no longer accurate? > > There should be no more corruption since commit 959217c84c27 ("pstore: > Actually give up during locking failure") - if we're bailing out, we > can't be causing corruption, I believe? Yeah, agreed. String content change is fine, the weird leading comma I'd like to do without. :) Thanks! -- Kees Cook