Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp3979431rdb; Wed, 30 Aug 2023 11:36:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzSQQKIGpOQv7RaaqjaZvqEDTqggjU0WfHnqquF81SJ9nbIeVkv7sI9Ls5RcmmFXY772L2 X-Received: by 2002:a05:6a20:8e24:b0:14c:5dc3:f1fe with SMTP id y36-20020a056a208e2400b0014c5dc3f1femr3549613pzj.41.1693420564610; Wed, 30 Aug 2023 11:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693420564; cv=none; d=google.com; s=arc-20160816; b=n8FFhzt0OcV21unDCKVfYAoh8bkr06dx2g92E/1IS1Rx03Qf79tLdtUfrHc0Wb/BLW x4sJ5TiO9PjkqFcz2BL3CJTURXD6JiVixqYnHWiKe6WTxsPX7bie78prXnmyvBYaZFpd lfASsjHZqTgrNU5J39yyjXN6sigL/yYJsSk/bd59mrZ8f8GR6pHQ1FQoZZEhidE0+9t7 x+2QZQhQi9aL7RBSQI+RqlbEeMJDWe9n6Ho1znGsOuAW2GHNLouLuj+7wuk0Ta9A17/J e3dgscnWFxsEyqXaWGgl0HHDxNwA2bSxgEhIqraNtRmxMZnMjBq9easTOqwcIe48068n 73gA== 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=w4rWGzIQGAKrWrm2Eo2DF/sa9ZU36wLeBkHUk/F8tS0=; fh=6tLur+qeZJ2+nmLcVtzQHrgRz0BHF/FpY2Yz2xnwPgU=; b=usHB+6xDSPRArTbB7NUSIlM21hfWhCfSSUYHbYLKXbHRe+eJPa1BTJS/WofH8d3nZX Y+rBYAmQmzc2eqbHOBF837h1qVLGSmatvKhtiMTT7vE5a+TQDdiBR8LdoLdXdR0qub2a z41seWOVfnn5xEcMBoBb4YbyCF/815st84/gJA/C7y01mNRyMwtBqMbQhp/9TumR9HUt j+hBWgCV3BGJTymBjUnxEEmbyDwU9ocsy072Xdz5m09r+wLAIy7HV2cbU4WFC6+8UJuP Q5uvU/r4iY2UJQ7CxwMnG37I4c2MuzDTjq1sM5q3KhIK429l6AGeVs2NuU+hkUYgquly TTSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L8OsP4zv; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eg8-20020a056a00800800b0068a59c0996fsi12166459pfb.191.2023.08.30.11.35.50; Wed, 30 Aug 2023 11:36:04 -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=@kernel.org header.s=k20201202 header.b=L8OsP4zv; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239178AbjH3GFg (ORCPT + 99 others); Wed, 30 Aug 2023 02:05:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239077AbjH3GFM (ORCPT ); Wed, 30 Aug 2023 02:05:12 -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 759BBCCA for ; Tue, 29 Aug 2023 23:05:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EECA962A06 for ; Wed, 30 Aug 2023 06:05:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11A41C433C8; Wed, 30 Aug 2023 06:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693375508; bh=pIEAeMZU01cu0V/hi9qtT63KB+MWUtdcr1EXhtHOuRk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=L8OsP4zv5gzmP0uGgcaIUG2DAQ0joO2f/CK6fbztCn0jfdksVQo5gAYHk+oH/MrR/ lRm9VHJKmtt40ME7QrBDJTwrEQg4H35WualfNFeVeASfHdZY9y+SsrjSjkJDs458Z0 yL6MRusr7zwvmNRShKVDXaL21Fgxg92ojLW/ADuI5Mh+jNL7KabkJtUP/VxZ83s9OT 3ip+bUlaOfSCG6YSLGILSBBaW34wFy5KIAtU7oN0ShKz/xrtKgpltOcMzAtzjiUcFc Fes8/pQKkmhDHSGGCYF8wOzMz4xL8E3D5HKx42HyOpsSVYfG+6Z2BTHqQHrgDzDMpl IuIXyz5rHXaYw== Date: Tue, 29 Aug 2023 23:05:06 -0700 From: Eric Biggers To: Ard Biesheuvel Cc: Linus Torvalds , Kees Cook , Kees Cook , linux-kernel@vger.kernel.org, Enlin Mu , "Guilherme G. Piccoli" , "Matthew Wilcox (Oracle)" , Yunlong Xing , Yuxiao Zhang Subject: Re: [GIT PULL] pstore updates for v6.6-rc1 Message-ID: <20230830060506.GA1015@sol.localdomain> References: <202308281119.10472FC7@keescook> <202308282035.5AFD431B@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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-kernel@vger.kernel.org Hi, On Tue, Aug 29, 2023 at 11:43:37PM +0200, Ard Biesheuvel wrote: > On Tue, 29 Aug 2023 at 20:04, Linus Torvalds > wrote: > > > > On Tue, 29 Aug 2023 at 10:29, Ard Biesheuvel wrote: > > > > > > This is an oversight on my part. The diff below plugs this into the pstore code > > > > Hmm. My reaction is that you should also add the comment about the > > "Work around a bug in zlib" issue, because this code makes no sense > > otherwise. > > > > Naturally. But pasting the comment into the email body seemed unnecessary. > > > Of course, potentially even better would be to actually move this fix > > into our copy of zlib. Does the bug / misfeature still exist in > > upstream zlib? > > > > I have no idea. You are the one sitting on the only [potential] > reproducer I am aware of, and there is nothing in the git (or prior) > history that sheds any light on this. Could you copy one of those EFI > variables to a file and share it so I can try and reproduce this? > > > Also, grepping around a bit, I note that btrfs, for example, just does > > that Z_SYNC_FLUSH, and then checks for Z_OK. None of this Z_STREAM_END > > stuff. > > > > Similarly, going off to the debian code search, I find other code that > > just accepts either Z_OK or Z_STREAM_END. > > > > So what's so magical about how pstore uses zlib? This is just very odd. > > > > AIUI, zlib can be used in raw mode and with a header/footer. Passing > the wbits parameter as a negative number (!) will switch into raw > mode. > > The btrfs and jffs2 occurrences both default to positive wbits, and > switch to negative in a very specific case that involves zlib > internals that I don't understand. crypto/deflate.c implements both > modes, and pstore always used the raw one in all cases. > > The workaround in crypto/deflate.c is documented as being specific to > the raw mode, which is why it makes sense to at least verify whether > the same workaround that pstore-deflate was using when doing raw zlib > through the crypto API is still needed now that it calls zlib > directly. I get the "pstore: zlib_inflate() failed, ret = -5!" messages on my system too, so I looked into it. What's happening is that the pstore records are coming from the efi_pstore backend, which has pstore_info::bufsize of 1024 bytes, but they decompress to more than 1024 bytes. Since pstore now sizes the buffer for decompressed data to only pstore_info::bufsize, lib/zlib_inflate correctly returns Z_BUF_ERROR. (BTW, I write "lib/zlib_inflate", not "zlib", since it was forked from the real zlib 25 years ago. Regardless, the problem isn't there.) I think we partially misinterpreted the functions like zbufsize_deflate() that Ard's patches removed. They seemed to be used only for getting the worst case compressed size for an uncompressed size of pstore_info::bufsize. Actually, they were used both for that, *and* for getting the uncompressed size to try to compress into pstore_info::bufsize. (Which is very weird, as these are two very different concepts.) So I think first we need to decide whether pstore should try to use compression to fit more than pstore_info::bufsize of data in each pstore record, as opposed to just shrinking the size of the record actually written. If yes, then this really needs some more thought than the previous code which seemed to do this by accident. If no, then the new approach is fine. BTW, what happens if someone was using a non-DEFLATE algorithm and then upgrades their kernel? Decompression can fail for that too. So maybe pstore just needs to consider that decompression of pstore records written by an older kernel can fail -- either due to the algorithm changing or due to the uncompressed size being too large for the new code -- and silence the error messages accordingly? How "persistent" do these persistent store records really have to be? - Eric