From patchwork Thu Jan 26 11:21:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 48600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp222993wrn; Thu, 26 Jan 2023 03:35:32 -0800 (PST) X-Google-Smtp-Source: AK7set+EeIyNlIxkDuT8IxsgVeQRjoPPFAZQlcxy3vb6bORxiFFxPsxFjMVCnL3zPi/7ExsIuM8N X-Received: by 2002:a17:90b:384c:b0:22b:f895:54bc with SMTP id nl12-20020a17090b384c00b0022bf89554bcmr1793609pjb.47.1674732931928; Thu, 26 Jan 2023 03:35:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674732931; cv=none; d=google.com; s=arc-20160816; b=ltsSoEXbDUdt73v9c5l/saV9mE0ARJmAvMIjN5aSL4mdD583wCEocC3b2at7mlM7TY 2MpguwPQik5rzBT0NhPJj4UwumcOfMnWtJplcfW82jcoucGKKPs26H/zp11tja/AlRX3 VBSMq5wloYwwzmSGCGR8OavwxkuVhNcWq0rPlskHlqH2oMySfzQFldFxrEIM19MYKx7v sPmlaF9lEqiNYoVkt0YVlR3rB3vTYw/K4djPCvvRKMNICPh25NTXI+32eqiReo91P1Ku VOurJ4VS+crv9LpaX80I2mtmQRmYxbbSzfjm89jBkEPg8Q5HuzRcy8T/ArsHSlrr0IYA yNsQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=KuYVbkFOAHDknv+bOxwxPr0hwpwZfK1Uwd5hYa4mmXc=; b=Ut4VwekuxWM6XcVMNfd6OLtHZbJuNEVUcSoDbInsk0WrIse/JQIF008wQpkIo3Ylrh oKDUs2Sn8DGihnJsSzwYf82El82vIjFYRnJEAhvAHfIjdgZJYR6em4oMDgygJt6NZkJb 2I9naJliLus6JlYIWvIEXQoj6PTGAlTtqtkNYh2gaLKf7JMpU/0HibviyfjlV6jI9/x5 0OY8sSueZ0HjjzrcZ0VSzau05mIPClAOInsbffLI0y3D42RsfkC9FlyzGg4d9jKmvmf2 fHLGm4zU1WPmZOpuz9UDeh0RbLz6/nKD2T0afAkZOkenc/Lup1eXny6Z7LkxijRs0flz 17Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uIXzC1Vz; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t23-20020a17090aba9700b002290c209ccdsi1313371pjr.150.2023.01.26.03.35.18; Thu, 26 Jan 2023 03:35:31 -0800 (PST) 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=uIXzC1Vz; 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 S237071AbjAZLXg (ORCPT + 99 others); Thu, 26 Jan 2023 06:23:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235097AbjAZLXf (ORCPT ); Thu, 26 Jan 2023 06:23:35 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8676B62250; Thu, 26 Jan 2023 03:23:34 -0800 (PST) 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 40681B81D67; Thu, 26 Jan 2023 11:23:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFAF4C433EF; Thu, 26 Jan 2023 11:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674732211; bh=66CKXAS/9EP3h8TINvZYNEfbZEZC0fHykS1xCI4vhh0=; h=From:To:Cc:Subject:Date:From; b=uIXzC1Vzni8t9BXgZoq8o0afdj8AMuiS7eTtEUEHkjTslxW6Ve/37BP0lHiIcbDIB q/MtyscQCcpASrh6Ey5zWSm/Ys7josHMN6CuiJeHBmnhtNoWcdMjJcjkJXpcrnboLk tP4nQpjYLWm657VvkR4kh6yjFtPyxkpoRRnxN9x6cqtA1EdsyZ4ipOsgG7hSjhhHyv LDeOqR0v8wIDZf7alQC/5bXPlDLROFwE2dBFqZp2864+LmvQmX2e9WJ9V/72kiEZVe 8NHbB7UBwO7rwkrYAt5nc6bdDNgs6utmzhlB7bW+hbB5/3cHkihmmMMqxlSlGh8fb+ pD93stJBo7ZRA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pL0Lx-0001Cy-8A; Thu, 26 Jan 2023 12:23:38 +0100 From: Johan Hovold To: Ard Biesheuvel Cc: Jeremy Kerr , Maximilian Luz , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , Steev Klimaszewski Subject: [PATCH] efivarfs: fix NULL-deref on mount when no efivars Date: Thu, 26 Jan 2023 12:21:29 +0100 Message-Id: <20230126112129.4602-1-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756084758788119920?= X-GMAIL-MSGID: =?utf-8?q?1756084758788119920?= The VFS calls kill_sb() also in case mount fails in get_tree(). Add the missing check to make sure that efivars has been registered also to kill_sb() to avoid dereferencing a NULL pointer when trying to remove efivar entries. Fixes: c3fd71b428b8 ("efivarfs: always register filesystem") Reported-by: Steev Klimaszewski Signed-off-by: Johan Hovold --- fs/efivarfs/super.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c index b67d431c861a..482d612b716b 100644 --- a/fs/efivarfs/super.c +++ b/fs/efivarfs/super.c @@ -246,6 +246,9 @@ static void efivarfs_kill_sb(struct super_block *sb) { kill_litter_super(sb); + if (!efivar_is_available()) + return; + /* Remove all entries and destroy */ efivar_entry_iter(efivarfs_destroy, &efivarfs_list, NULL); }