From patchwork Fri May 26 17:16:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 99587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp643633vqr; Fri, 26 May 2023 10:32:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6EXqzYP1LPLsGaSX17YSWPLDImBceb3ra5pyHmUVwfuZIIYJ5ml32Q12o+o0wKj4QKSoaJ X-Received: by 2002:a05:6a00:391c:b0:64f:52c9:ddd5 with SMTP id fh28-20020a056a00391c00b0064f52c9ddd5mr4912483pfb.34.1685122365300; Fri, 26 May 2023 10:32:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685122365; cv=none; d=google.com; s=arc-20160816; b=XEwrYcuQtEoAbnhjjIMySZY112nwbPwDHTvKzDiN1Z4QftnJVnIFxZjQUFZTFuGWdO VZPSXEsnMM2nZj+NpjX5YQ3f9LPV1EVhyJ9BkOOkftC+u8fzRNpM9Y/98/2rWaJMeGPZ IHhpBG9xRG9bfDRbXokBPI+ZL4co0q0UMS0OJ+qAzcyCVEos4dHYLpxFVXZK3r0vBHYd 5rAKKgJDM7wkleGzvYkTybGDy3a8a7RuER8Ggz3L2jy/oK7xqbwEfRGsBTNhP6JcgsUh xio0UKcufCSdU8DkMySPyvr6aSwILsa96Wxa4Sb+L1BCyp/QmwRxH24ntDZPApfqMGlc +Hng== 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 :feedback-id:dkim-signature:dkim-signature; bh=a6e+m1dGX2S9IHv+LEb0KF8KfjhX5NO7nh1vFg/in2g=; b=B9UN55CCMUvERyLkUOYPTCNgw5WbdgY4m/6BcmVuzUpUU/fPeWLjenruYnDrf9W5ka M3jZZiy/qrLdbo3zqxHQCP1Q3h97I9L1l+kLIzoEwbRa6dHyP6rlKMOuTwroaXjbTQ5g VaeZ6jTqpBNTPqMqMcaGxUaLY9SMrF57SKLCIKa6KhQ8lLpv4hhkzIiWxK+d9NyT3sQt qE81pMtylI3uDZ99cV8fjQ/1/UGsJyM7jkBBNsHpi9/a1Pim2SVl/uvt4TW6liRm66KR 0rDHITMqKYXgE8py3c5/IcaSl1oQHLlPOlM9Vmvk6QN2shx+t6w/5gExcumVAxyjTwEs Jt8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@squebb.ca header.s=fm2 header.b=TNK1CLoT; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=YLVMY9FM; 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 j21-20020a637a55000000b0053b8f59ac25si819020pgn.194.2023.05.26.10.32.33; Fri, 26 May 2023 10:32:45 -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=@squebb.ca header.s=fm2 header.b=TNK1CLoT; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=YLVMY9FM; 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 S242581AbjEZRRe (ORCPT + 99 others); Fri, 26 May 2023 13:17:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237418AbjEZRRU (ORCPT ); Fri, 26 May 2023 13:17:20 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4661CF2; Fri, 26 May 2023 10:17:17 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B319A5C00DC; Fri, 26 May 2023 13:17:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 26 May 2023 13:17:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=squebb.ca; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1685121436; x= 1685207836; bh=a6e+m1dGX2S9IHv+LEb0KF8KfjhX5NO7nh1vFg/in2g=; b=T NK1CLoTndCbe2AqPL2bBK38QMNjJTuAAbabkVZnzGUJEIjykcEzqFp11Ryor0BvB eG8bfjobd/ERFsg7Okn4xtydB+al2wtbyv2RQ+ehTkboGGqgZ/5rbdyVN+kflsCL 3drRe3FZqoVThy6OeSIu0qdaXcPwly2l1XRCwF3CY8518xTlYN3R1mT5Q8UTIPh1 DooeJIAG1rWGWzatFU/nzvaGljhcH5Mr4lOvUBVvq4E4tq8XxE06XURa0dj5/6/3 AVZOE8iCxK06N5XQC82t8EOZG4u+0vEnRtoY7ir23Vm4cn6ztmXG5s59YwDIzepa zZlSi7VEoGiniRz8TNg1A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1685121436; x= 1685207836; bh=a6e+m1dGX2S9IHv+LEb0KF8KfjhX5NO7nh1vFg/in2g=; b=Y LVMY9FMRyfyLPM7j3KEP2oZ+xk/MFaHJMTkd+WsqZMlHRXKq4GE+mggW266UEflu 5EUi840C/1Mt6DRyGLkEeuklrsmAA2KnINPy+syT+PaByJ1MnEH6qB/tE65z+63X fdT9EIwNTFj+Wwu1b6ZGPtz6pDUBbwuXhoHR+I2cxZccaryTEkUoxlRexD0WPtx/ ubdTJuHdwuRmR7OLjf/A+j+0uNDMano+KLaQfSkYruOXA/XflMaimL7g7gv9GhdC PYG+oC1Zrq11+uaxhchiwVPGPXnsuAhpH59w3X4bi21oVOBnlmj3Z4xmHKX7aRPn NocrBzsc5A/mjMUTFcDPw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejledguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecuogetfedtuddqtdduucdludehmdenucfjughrpe fhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforghrkhcurfgvrghr shhonhcuoehmphgvrghrshhonhdqlhgvnhhovhhosehsqhhuvggssgdrtggrqeenucggtf frrghtthgvrhhnpeeftddvjeefleffvefhgfejjeehudetteeigeeugfekhffhgeejudeu teehgfdvffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehmphgvrghrshhonhdqlhgvnhhovhhosehsqhhuvggssgdrtggr X-ME-Proxy: Feedback-ID: ibe194615:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 26 May 2023 13:17:16 -0400 (EDT) From: Mark Pearson To: mpearson-lenovo@squebb.ca Cc: hdegoede@redhat.com, markgross@kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/5] platform/x86: think-lmi: mutex protection around multiple WMI calls Date: Fri, 26 May 2023 13:16:58 -0400 Message-Id: <20230526171658.3886-5-mpearson-lenovo@squebb.ca> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230526171658.3886-1-mpearson-lenovo@squebb.ca> References: <20230526171658.3886-1-mpearson-lenovo@squebb.ca> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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?1766896832493706891?= X-GMAIL-MSGID: =?utf-8?q?1766978868932065165?= Add mutex protection around cases where an operation needs multiple WMI calls - e.g. setting password. Signed-off-by: Mark Pearson --- Changes in v2: New commit added after review of other patches in series. Changes in v3: Simplified mutex handling as recommended. drivers/platform/x86/think-lmi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c index 64cd453d6e7d..86185358dba2 100644 --- a/drivers/platform/x86/think-lmi.c +++ b/drivers/platform/x86/think-lmi.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -195,6 +196,7 @@ static const char * const level_options[] = { }; static struct think_lmi tlmi_priv; static struct class *fw_attr_class; +static DEFINE_MUTEX(tlmi_mutex); /* ------ Utility functions ------------*/ /* Strip out CR if one is present */ @@ -437,6 +439,9 @@ static ssize_t new_password_store(struct kobject *kobj, /* Strip out CR if one is present, setting password won't work if it is present */ strip_cr(new_pwd); + /* Use lock in case multiple WMI operations needed */ + mutex_lock(&tlmi_mutex); + pwdlen = strlen(new_pwd); /* pwdlen == 0 is allowed to clear the password */ if (pwdlen && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen))) { @@ -493,6 +498,7 @@ static ssize_t new_password_store(struct kobject *kobj, kfree(auth_str); } out: + mutex_unlock(&tlmi_mutex); kfree(new_pwd); return ret ?: count; } @@ -987,6 +993,9 @@ static ssize_t current_value_store(struct kobject *kobj, /* Strip out CR if one is present */ strip_cr(new_setting); + /* Use lock in case multiple WMI operations needed */ + mutex_lock(&tlmi_mutex); + /* Check if certificate authentication is enabled and active */ if (tlmi_priv.certificate_support && tlmi_priv.pwd_admin->cert_installed) { if (!tlmi_priv.pwd_admin->signature || !tlmi_priv.pwd_admin->save_signature) { @@ -1031,7 +1040,6 @@ static ssize_t current_value_store(struct kobject *kobj, if (ret) goto out; } - ret = tlmi_save_bios_settings(""); } else { /* old non opcode based authentication method (deprecated)*/ if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) { @@ -1071,6 +1079,7 @@ static ssize_t current_value_store(struct kobject *kobj, kobject_uevent(&tlmi_priv.class_dev->kobj, KOBJ_CHANGE); } out: + mutex_unlock(&tlmi_mutex); kfree(auth_str); kfree(set_str); kfree(new_setting);