Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1373788rwb; Thu, 19 Jan 2023 09:45:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXtvyIYbxgpYAPRZr+bVn4DAL74dtp9e2HhShUNnH6ZJqHpfpBHE8pcQ3BKuA1BxOgdlCbNw X-Received: by 2002:a17:902:9b97:b0:193:3314:540d with SMTP id y23-20020a1709029b9700b001933314540dmr11361715plp.51.1674150340700; Thu, 19 Jan 2023 09:45:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674150340; cv=none; d=google.com; s=arc-20160816; b=EbNKjzwwgowF9GaCd2jsMXqkTQFvjAjNkjlrBcF5GriKLyNZ1xvzcxHFhbPTTFBMbM OqCghabDK4OPCwUF9fiRwlzj36Xj+ZgncZ5NmZtYqAb8j+i4mkTYSMEkefU/HX/2SkCv qXXRRAltRHzyXHKaFIkmNpEAOzhIJWiGpFi5RG95SG8/YxI3+0wdYx03lxxvYzCG5nGy po7XtQfxrwvXwNmPNBE2VA7oN11TJ5Lhb0UnmuaxWTHyMTjkC0gR7c6bss1FtodLOlVC JM4QJgzjokb7/o9f9GknABPrXtXGOdKRLAuJTEaGTyz9SuN76ocv1nfxnn/326hYcPHj QRrg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a1709027c8700b0019488af7e99si14317197pll.581.2023.01.19.09.45.35; Thu, 19 Jan 2023 09:45:40 -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 + 45 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 Content-Transfer-Encoding: 8bit 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 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); -- 2.38.2