From patchwork Thu Jan 19 16:42:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 45861 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp435955wrn; Thu, 19 Jan 2023 08:56:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXuyJMmMPNKBmmPTQB8buIm0rSJFhpQ7ciUaf3M9Z8d1ByIgjAM26FTJ36i06zPA98h2zTAJ X-Received: by 2002:a17:907:7f14:b0:84d:3e5b:7c02 with SMTP id qf20-20020a1709077f1400b0084d3e5b7c02mr10767669ejc.22.1674147415583; Thu, 19 Jan 2023 08:56:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674147415; cv=none; d=google.com; s=arc-20160816; b=qdRLBW8O+z5Ja6gwoqF1XgSnSkv40Q28g6XDtMDLgBFBtD6XB6tK7oR+fjgDs8Ww9e t3YHR2a7MqJszHppIlO4k/C2vlGYuyUSWrObs64VqATJKJshl238VpnNmOg23YtmaKRP aZO4m4NmTHltbRkcHBEV+vrYmWtIaNyKo4yy8ZskyMIPJZnwBNwY+qDJinWmEXaSaUbP DEx2pxz48ywZ/szGXm6FhHNwjFVWLHfvN4fP3qJoHsHDqHW7F5MKqhlFaIcVXYCVACUr MIIfI8OZL/dfTUvpTvhiAB77WnRRGtpFtfZY1QWxvT9EEIFGqqSjKWHDeDZnQfV9XgEO 1n7Q== 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=Rq0KuYbJtVEpo5YGCcj7QfqZwlDW9fGVxu1e1R6BqdM=; b=W703SaSGo6AtqFYbZrm2MBHsv8LD2Opf5fCdordtJ2gekq7PEyethO9opE986kplyK 1G2FazSnBlWdZBLekFXm6bDRlhPMIxdM+88nEQtkU4fwuY/M4jI3NmwWvo/73pEda2/l q6MNwvYPbUMPndl6pV3RomNMbZayPnRPalWR0Nescypf85xLUCwaHoPv1sI1+lSCL6HN evPgdqEHgVAqYRzbAnnKcvnhqm5KSzaX1W7uO7nuDeJYeRz4UcfrQphJ/Ym42LngR3RA h62cjsIdPOyMGRfHuGYHWWqxnyRQNP8/SsF8f1TAYucf59V9CQIZKUSeX0HN16dseJEM xjrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QvBnUIlJ; 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 hw9-20020a170907a0c900b008774ec3fe91si6963070ejc.647.2023.01.19.08.56.32; Thu, 19 Jan 2023 08:56:55 -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=QvBnUIlJ; 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 S230271AbjASQqA (ORCPT + 99 others); Thu, 19 Jan 2023 11:46:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbjASQpv (ORCPT ); Thu, 19 Jan 2023 11:45:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E72458975; Thu, 19 Jan 2023 08:45:49 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 9A64761CDC; Thu, 19 Jan 2023 16:45:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2EB5C433F1; Thu, 19 Jan 2023 16:45:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674146748; bh=XeXJuV70b8QQ89031T2UsnyGwGhNXA27WLTobdUHe78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QvBnUIlJA0r4hT8+uu0mSag3a39SFxvH1ekgdar6RSpWa9Cqdh0t9UVAMzwVdJ66t Tnujp0eswYce5xvH99u9CXa+OocodvEkvGLDQ5+w9e8R7kx3mTkMHg+BBlJTZ8Onwj wEhodzItoVhF/usjpg7axTNYqWXBx8EtcycfZnSUH8I208NKyRBTRU24o4T+6gcw5M Ny8dQ5LS0NpHnCF9yvh3DzP9ay09XeF+4AtiiQFK1lIiNOYzOd1hj1K5i+0hKUEnS8 f/wMFhIk0q7m5ualI0qSNQA93/egjP+FTwooyePpgHQIZNFpKtKct0UkvaksxSimyr 1vWwdU2DyIofg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pIY3M-0007Mx-AT; Thu, 19 Jan 2023 17:46:16 +0100 From: Johan Hovold To: Ard Biesheuvel Cc: Matthew Garrett , Jeremy Kerr , Maximilian Luz , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 4/4] efi: efivars: prevent double registration Date: Thu, 19 Jan 2023 17:42:55 +0100 Message-Id: <20230119164255.28091-5-johan+linaro@kernel.org> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230119164255.28091-1-johan+linaro@kernel.org> References: <20230119164255.28091-1-johan+linaro@kernel.org> 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?1755470800782257466?= X-GMAIL-MSGID: =?utf-8?q?1755470800782257466?= Add the missing sanity check to efivars_register() so that it is no longer possible to override an already registered set of efivar ops (without first deregistering them). This can help debug initialisation ordering issues where drivers have so far unknowingly been relying on overriding the generic ops. Signed-off-by: Johan Hovold --- drivers/firmware/efi/vars.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c index f34e7741e0c3..bd75b87f5fc1 100644 --- a/drivers/firmware/efi/vars.c +++ b/drivers/firmware/efi/vars.c @@ -62,18 +62,27 @@ EXPORT_SYMBOL_GPL(efivar_is_available); int efivars_register(struct efivars *efivars, const struct efivar_operations *ops) { + int rv; + if (down_interruptible(&efivars_lock)) return -EINTR; + if (__efivars) { + pr_warn("efivars already registered\n"); + rv = -EBUSY; + goto out; + } + efivars->ops = ops; __efivars = efivars; pr_info("Registered efivars operations\n"); - + rv = 0; +out: up(&efivars_lock); - return 0; + return rv; } EXPORT_SYMBOL_GPL(efivars_register);