From patchwork Thu Oct 13 21:06:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 2372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp483753wrs; Thu, 13 Oct 2022 14:14:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM42y44YY7ihDxPtOaQylv3Y4PXFVywdtFSpXfNZcXhnbokfWEE5NvkK45LBoWk+jMX0PzpJ X-Received: by 2002:a17:902:c942:b0:180:3f94:2975 with SMTP id i2-20020a170902c94200b001803f942975mr1934992pla.50.1665695653407; Thu, 13 Oct 2022 14:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665695653; cv=none; d=google.com; s=arc-20160816; b=iPBtM7m/6MYLubqXqYIt9vB90wwzs5Ly9YczABzR857yCknmnbNZ/V6IJwRRlNHTAr HGtg9/1WaIfA15aTFozYuJBXmobReDcvL8RRA7LCuritrAIJ51xRQv+feQofUvkmaOuw sahWNcgy7G8ee7rnskldF9SmXkt3aVoid39c+LWwAQWd11u+bm82XY4rJjyVXxJjXozJ fjBtUZaKm5ElVgOps61sWO8C6sIvh5Fb/hw7ubq2pGXNjg6prdWDyhyQrBqhCHmnJOJp amnGw/b87s6+eeXDEm/Y6k64WTSmPz+ScRqVPlLAC5PgWjrr1p+s8wWXd8z3opfBuSLC KOTw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tZIWksLvbZf3hKAivkvuzlnH7vev2LNtmjEPqqMctpQ=; b=TrUFPrnTepqs+AImiXhhsWn7OFxZ5Td55YqfcVgshQ1pRN1KdkPHx2665lS6fINjpS CuhlDJeXyU1iS8MS8PLdR7XzcvvLlec5L/a9Kh7YCW9RyvlIj3khc2UAo73VtRF45Rx2 XQam0iHmpR8IgEO4rHm1X2wDII0nriOAeIuvvmp8fExPSBDxfTFuCPLG/kwNhpSbJgcq SL0pWpgHCKwYtIMDqcmZ8wBY/NsuqGTjCrA2FaHs4vSdfMWRLDXheKe7EeyNDXZXNl50 QENLPbK69jtoVFB1wfxbl4i4aDVyMuHsCCtvPw7mT1Yxw8yo24r/JR3ynyNmut2kSsic zuxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=a5Q74KM2; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u6-20020a631406000000b00464ee7492adsi583887pgl.722.2022.10.13.14.14.01; Thu, 13 Oct 2022 14:14:13 -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=fail header.i=@igalia.com header.s=20170329 header.b=a5Q74KM2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbiJMVLH (ORCPT + 99 others); Thu, 13 Oct 2022 17:11:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229696AbiJMVLE (ORCPT ); Thu, 13 Oct 2022 17:11:04 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB2E92B189; Thu, 13 Oct 2022 14:10:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=tZIWksLvbZf3hKAivkvuzlnH7vev2LNtmjEPqqMctpQ=; b=a5Q74KM2d0akGfotwLs4Oze7xd 5/ohN2Rdfcek3Yqthbqc2LGy9joEXU4R5QpeNAnDlLzf1ha5JAcbRNncDqmQtHb2A80nnOQRND1ey DMV3d3HpEX7Ctu2BWqyjl6J4hy4X/Y1bDZhh4mo22vep7vA27FVULyLrg5NfBoiXKx12Z2IgsBVyH Fdn2HaMiVb9xNaMVxsijAG0HiClg1pGj8EGtrZVckcDsuYYgrT0B8/IuRqvM9g3vk6s3ToCi34RkO lXJ2bFQ/bWJqwMTmM1DGjbLQtQ1IYSKSltQi3nDMmfCPC/acrPq3UyHoenhrQyc7/MVooEIcJzJTN +EaVCKHA==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1oj5Tk-0010yp-8K; Thu, 13 Oct 2022 23:10:57 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-efi@vger.kernel.org, kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, ardb@kernel.org, "Guilherme G. Piccoli" Subject: [PATCH V2 1/3] pstore: Alert on backend write error Date: Thu, 13 Oct 2022 18:06:46 -0300 Message-Id: <20221013210648.137452-2-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013210648.137452-1-gpiccoli@igalia.com> References: <20221013210648.137452-1-gpiccoli@igalia.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746608485586866808?= X-GMAIL-MSGID: =?utf-8?q?1746608485586866808?= The pstore dump function doesn't alert at all on errors - despite pstore is usually a last resource and if it fails users won't be able to read the kernel log, this is not the case for server users with serial access, for example. So, let's at least attempt to inform such advanced users on the first backend writing error detected during the kmsg dump - this is also very useful for pstore debugging purposes. Signed-off-by: Guilherme G. Piccoli Acked-by: Ard Biesheuvel --- V2: - Show error message late, outside of the critical region (thanks Kees for the idea!). fs/pstore/platform.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 06c2c66af332..cbc0b468c1ab 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -393,6 +393,7 @@ static void pstore_dump(struct kmsg_dumper *dumper, const char *why; unsigned int part = 1; unsigned long flags = 0; + int saved_ret = 0; int ret; why = kmsg_dump_reason_str(reason); @@ -463,12 +464,21 @@ static void pstore_dump(struct kmsg_dumper *dumper, if (ret == 0 && reason == KMSG_DUMP_OOPS) { pstore_new_entry = 1; pstore_timer_kick(); + } else { + /* Preserve only the first non-zero returned value. */ + if (!saved_ret) + saved_ret = ret; } total += record.size; part++; } spin_unlock_irqrestore(&psinfo->buf_lock, flags); + + if (saved_ret) { + pr_err_once("backend (%s) writing error (%d)\n", psinfo->name, + saved_ret); + } } static struct kmsg_dumper pstore_dumper = { From patchwork Thu Oct 13 21:06:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 2367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp483400wrs; Thu, 13 Oct 2022 14:12:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6s+kQ/mTCxEraEd2FZq9vozjdzOG8YIkD8ZHzpI44jMlyKqOobHVzijIrDSRFb+aGuvJZj X-Received: by 2002:a17:902:d70e:b0:178:2d9d:ba7b with SMTP id w14-20020a170902d70e00b001782d9dba7bmr1942997ply.90.1665695576345; Thu, 13 Oct 2022 14:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665695576; cv=none; d=google.com; s=arc-20160816; b=S3NqNgNC4H/eULU8qT7VmxsJj/NV1qPH3INipfcl8jBADUDt5kd9gUkQscSK56vn4P GVK1lOd/mlEe2kVXvEzjgT6BZpSZzrY4xZdB523QXvhvuUmao1slSRsJP7IAEbfbCgy9 Dkb+xzIyJ6I77CTQHG1wVHRBN/kS2lFdjgehgwcfA1MhV2IUsgtO6YaytSxY/QMrz2aT QhG97GAlooIunSNL6v9A9DRpwPDXEJCCQUpCOkLrzz1nNBwBAcWJ3veRmZ/vRzf8o5Ns fwqm5ggvibCUM5Cg3GWqGGNhhp+7PbLNrdpHiRb2HTBk/Emv03iuHL6OE+RWIv55VSQT 0jpw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GcklzwrLgeVXmrc9kawBXnG2QLvECr568P4pKI8MuFw=; b=O2QJmdcyBjTqkhckgH8vdGPo1NH+PoDmYTjKt9igtl2B+u0hnkSSYCYw7lt3G70ZCv t6olP+ofYotjjhJtcRs1KpjwAqN0fNhZEJ/ZZpQwTKOvCWkGsGjm+YcemJLK5U16mfF5 sw97FW8KDpxItwpxD1ULFVROKBsqaqZh4CXEjw9PDxkq489PjJzdi2C3ZKC6cMKA5MKs Tso1ZSHmSIsbrFZlBwkuWP4QI8gx/lx56vWcbonMTaRHEhZEAwyX27UKPzmbJgrR9kVr Q5Hki9xTaowqJy82l+2jelU2IAjNzifU8IAx+25NZYYRzFdTW/C5s1Rwp9t8KX++bKaQ YImw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=BrDPtCLA; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a656a02000000b00452bad3abcfsi639182pgu.324.2022.10.13.14.12.43; Thu, 13 Oct 2022 14:12:56 -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=fail header.i=@igalia.com header.s=20170329 header.b=BrDPtCLA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229879AbiJMVL1 (ORCPT + 99 others); Thu, 13 Oct 2022 17:11:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229801AbiJMVLU (ORCPT ); Thu, 13 Oct 2022 17:11:20 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD42A18F91B; Thu, 13 Oct 2022 14:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=GcklzwrLgeVXmrc9kawBXnG2QLvECr568P4pKI8MuFw=; b=BrDPtCLAEqR1VvN0IuOE/DgCzT tBBEh7LHeyN1ZhVNYID1zIqeGO/7a9E9hIARvHp/F1DAx3lnJsc3fj5v/6cK7++KHCreXrewhNGBn duu2ZbRtli6s+BYpqFWJ5oA2OaZo8ihKZ9qBCBcnCnWMHspHWzTSxbcaP3GQAkIbH55NUdaWMNLy5 PCC5gF0PSP36WeF07kyV5fD0x16REiu6K57wIQpAt5Mx/atoRzKEyBJrnREKe+/6rBX/rNtjFyl93 zNA2EL9YSHln9xMZ8qxN0j+sVQ05MvjCuEj5sckgmGH5RDqKgFeJaB3EotBNj9s0z7/1OHZDq//fr HnDf9VRg==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1oj5U4-0010zH-BX; Thu, 13 Oct 2022 23:11:17 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-efi@vger.kernel.org, kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, ardb@kernel.org, "Guilherme G. Piccoli" Subject: [PATCH V2 2/3] efi: pstore: Follow convention for the efi-pstore backend name Date: Thu, 13 Oct 2022 18:06:47 -0300 Message-Id: <20221013210648.137452-3-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013210648.137452-1-gpiccoli@igalia.com> References: <20221013210648.137452-1-gpiccoli@igalia.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746608404416385887?= X-GMAIL-MSGID: =?utf-8?q?1746608404416385887?= For some reason, the efi-pstore backend name (exposed through the pstore infrastructure) is hardcoded as "efi", whereas all the other backends follow a kind of convention in using the module name. Let's do it here as well, to make user's life easier (they might use this info for unloading the module backend, for example). Acked-by: Ard Biesheuvel Signed-off-by: Guilherme G. Piccoli --- V2: - Added Ard's ACK - thanks! drivers/firmware/efi/efi-pstore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c index 3bddc152fcd4..97a9e84840a0 100644 --- a/drivers/firmware/efi/efi-pstore.c +++ b/drivers/firmware/efi/efi-pstore.c @@ -207,7 +207,7 @@ static int efi_pstore_erase(struct pstore_record *record) static struct pstore_info efi_pstore_info = { .owner = THIS_MODULE, - .name = "efi", + .name = KBUILD_MODNAME, .flags = PSTORE_FLAGS_DMESG, .open = efi_pstore_open, .close = efi_pstore_close, From patchwork Thu Oct 13 21:06:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 2368 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp483495wrs; Thu, 13 Oct 2022 14:13:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM41mve7eXQkTtTUxh++FImDFbYSMzdH7FgIUFUyqnicaqLGh5mAA0ifDzXeQyD3wnbSf0eu X-Received: by 2002:a17:907:743:b0:740:ef93:2ffc with SMTP id xc3-20020a170907074300b00740ef932ffcmr1245809ejb.514.1665695593718; Thu, 13 Oct 2022 14:13:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665695593; cv=none; d=google.com; s=arc-20160816; b=elRJbIOTROiaE+wLy+dHxOxkv4FABCu6YdyEOtsY1C2a9/HfYorqIcFGdLjZd139Qc +Cz0imVc+YvpWpg1slO0q7tlwcn2HZcyFtq1mZWYM80DwG0Cnu+yt3gBEo3W43mcpkWN 27A3spvZcyPM5Go7XKv6Osao8prB+xhKERv/Qj3fZHNBs4VktkPMhJmucLZZOOwy/0ae CJMXZ/4m7ZMtNgPwYTjy4LiOGtemzAgJMOz8MUenTVZW7X1+Ey3AB+pjua10G+eLsPmJ B8UAScBwcPxmQ//DrR7xfLn8dVHw7lLHBOjYKOAJ7/RansxjbW7zYXdU3IufB9mv8S8m MOeg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zxaa0wrHR2Xk0QAem3sMoc/ttgR5Mks9tB52oq2LMoI=; b=q6cKaW7ZtpNzNEDC5MHWWWXBEOVcgv6a8FbtVnLNm1Zm7Qa3PLm9yk1STugFcjVax8 mofvewCXfMQKn6yx1BLxnOAfd2Ohko9oYnzuGpxu5LT6+NHaydFIxVLjVH/xEeEf0MVL KGGDGM/UiBIjiBMecA151NN30Cr/owr4HrK61wVjl5tTNvBtnK6ZquWB+rHaKVYjRkYQ 8IRm1H19FJnrJpGT4AwsNE3yCxRSE0yq7PiJ9IgyS21qCEr1IovxSv62L72C51tf/QcN huuma/yvIJebmbX4k2yN5tU+PGlD3H5GpqNiSJtT8w/g8/8djcYeKlEFAjMe708IAJF+ gTwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=dIqmKbS9; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x7-20020a170906148700b0078200f94d06si626800ejc.237.2022.10.13.14.12.49; Thu, 13 Oct 2022 14:13:13 -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=fail header.i=@igalia.com header.s=20170329 header.b=dIqmKbS9; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229811AbiJMVLp (ORCPT + 99 others); Thu, 13 Oct 2022 17:11:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbiJMVLl (ORCPT ); Thu, 13 Oct 2022 17:11:41 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC9CC18F922; Thu, 13 Oct 2022 14:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=zxaa0wrHR2Xk0QAem3sMoc/ttgR5Mks9tB52oq2LMoI=; b=dIqmKbS9ZsZSomzzqJQLshwLGd Hpi7MiR63y0OnqraByMoaYaKLWJVpZBjjSq2MURwcN8ln/FIqz/f/x2iUdbRep/j0TkhNWW1pW5tJ nOcemyt+qiusxHo52qEvdh8O1QwyGFJEChAE80mQTx2DHnNSZkJ45Bo/dMyODtRaNMZEA4TiUOasN qlVoN2P/lFJz9N23Tf45XgfgewIf0QhDp/1lk9rIGZ01FLiwGTfyUpVwtmu50urQUediF1V+zK2OP 9hEQPQhT6HBDzUF3K5W74HOdvkj6s29Ou/IYvqwVSMZ2QFKDSTpWwxDJ1Bet68fYfuFu9ACMD1jCm 1L7ts2Fg==; Received: from 201-43-120-40.dsl.telesp.net.br ([201.43.120.40] helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1oj5UL-0010za-VR; Thu, 13 Oct 2022 23:11:34 +0200 From: "Guilherme G. Piccoli" To: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-efi@vger.kernel.org, kernel-dev@igalia.com, kernel@gpiccoli.net, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, ardb@kernel.org, "Guilherme G. Piccoli" Subject: [PATCH V2 3/3] efi: pstore: Add module parameter for setting the record size Date: Thu, 13 Oct 2022 18:06:48 -0300 Message-Id: <20221013210648.137452-4-gpiccoli@igalia.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013210648.137452-1-gpiccoli@igalia.com> References: <20221013210648.137452-1-gpiccoli@igalia.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746608422788491564?= X-GMAIL-MSGID: =?utf-8?q?1746608422788491564?= By default, the efi-pstore backend hardcode the UEFI variable size as 1024 bytes. The historical reasons for that were discussed by Ard in threads [0][1]: "there is some cargo cult from prehistoric EFI times going on here, it seems. Or maybe just misinterpretation of the maximum size for the variable *name* vs the variable itself.". "OVMF has OvmfPkg/OvmfPkgX64.dsc: gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 OvmfPkg/OvmfPkgX64.dsc: gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 where the first one is without secure boot and the second with secure boot. Interestingly, the default is gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400 so this is probably where this 1k number comes from." With that, and since there is not such a limit in the UEFI spec, we have the confidence to hereby add a module parameter to enable advanced users to change the UEFI record size for efi-pstore data collection, this way allowing a much easier reading of the collected log, which is not scattered anymore among many small files. Through empirical analysis we observed that extreme low values (like 8 bytes) could eventually cause writing issues, so given that and the OVMF default discussed, we limited the minimum value to 1024 bytes, which also is still the default. [0] https://lore.kernel.org/lkml/CAMj1kXF4UyRMh2Y_KakeNBHvkHhTtavASTAxXinDO1rhPe_wYg@mail.gmail.com/ [1] https://lore.kernel.org/lkml/CAMj1kXFy-2KddGu+dgebAdU9v2sindxVoiHLWuVhqYw+R=kqng@mail.gmail.com/ Cc: Ard Biesheuvel Signed-off-by: Guilherme G. Piccoli --- V2: - Fixed a memory corruption bug in the code (that wasn't causing trouble before due to the fixed sized of record_size), thanks Ard for spotting this! - Added Ard's archeology in the commit message plus a comment with the reasoning behind the minimum value. drivers/firmware/efi/efi-pstore.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c index 97a9e84840a0..827e32427ddb 100644 --- a/drivers/firmware/efi/efi-pstore.c +++ b/drivers/firmware/efi/efi-pstore.c @@ -10,7 +10,9 @@ MODULE_IMPORT_NS(EFIVAR); #define DUMP_NAME_LEN 66 -#define EFIVARS_DATA_SIZE_MAX 1024 +static unsigned int record_size = 1024; +module_param(record_size, uint, 0444); +MODULE_PARM_DESC(record_size, "size of each pstore UEFI var (in bytes, min/default=1024)"); static bool efivars_pstore_disable = IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE); @@ -30,7 +32,7 @@ static int efi_pstore_open(struct pstore_info *psi) if (err) return err; - psi->data = kzalloc(EFIVARS_DATA_SIZE_MAX, GFP_KERNEL); + psi->data = kzalloc(record_size, GFP_KERNEL); if (!psi->data) return -ENOMEM; @@ -52,7 +54,7 @@ static inline u64 generic_id(u64 timestamp, unsigned int part, int count) static int efi_pstore_read_func(struct pstore_record *record, efi_char16_t *varname) { - unsigned long wlen, size = EFIVARS_DATA_SIZE_MAX; + unsigned long wlen, size = record_size; char name[DUMP_NAME_LEN], data_type; efi_status_t status; int cnt; @@ -133,7 +135,7 @@ static ssize_t efi_pstore_read(struct pstore_record *record) efi_status_t status; for (;;) { - varname_size = EFIVARS_DATA_SIZE_MAX; + varname_size = record_size; /* * If this is the first read() call in the pstore enumeration, @@ -224,11 +226,20 @@ static __init int efivars_pstore_init(void) if (efivars_pstore_disable) return 0; - efi_pstore_info.buf = kmalloc(4096, GFP_KERNEL); + /* + * Notice that 1024 is the minimum here to prevent issues with + * decompression algorithms that were spotted during tests; + * even in the case of not using compression, smaller values would + * just pollute more the pstore FS with many small collected files. + */ + if (record_size < 1024) + record_size = 1024; + + efi_pstore_info.buf = kmalloc(record_size, GFP_KERNEL); if (!efi_pstore_info.buf) return -ENOMEM; - efi_pstore_info.bufsize = 1024; + efi_pstore_info.bufsize = record_size; if (pstore_register(&efi_pstore_info)) { kfree(efi_pstore_info.buf);