Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp718405rwd; Thu, 25 May 2023 03:00:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6eTg6Okv25sT6/IrXSLWPfTKJ5FB+hb4zaPtTUaFCcPIRsY5l3WY4hKfUucv4S8WT1Qfz3 X-Received: by 2002:a05:6a00:1d0d:b0:64d:2d26:71c with SMTP id a13-20020a056a001d0d00b0064d2d26071cmr2506977pfx.1.1685008807694; Thu, 25 May 2023 03:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685008807; cv=none; d=google.com; s=arc-20160816; b=UrS3kERJ5OcEOW/Oj9K/ePXBGzeKGR4ti8rPXi8ZpDXG6X7mbZCBKvLgy//8qoDAPU c3eNn8gM2ZkTwvxpYc4dV3LOmhnVnbF4ZCubVRELyveFj8uYWa6aLd3PRX7JcNEHBxlX vnhFvOiCH2Nrbukf1ka8M9ZEtm5kpu9q2p5ydDJsvQuXWNbSshXunaT7JuAqU/M5zTvt lznBKERuX9+zwlWn4ygT9AUpNclKDANumsIF/PNdgs1aldh4EhQkxlBTFu26Uo+mhV8h O/py2+2LA1bBVoS/bmfpZtbcYv6U9tcDZQj4Kfp7IDs+DzBwyxXxJFlfkS/EajSVPuei c3Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=T483GshQ1etV4/B80hSTyHnl4OtRX6eMmZK03OF9d2k=; b=pCjFmwcHdXd7Cvi6k5eaWE/29io089uetfdWiMn+mg6XkaB7jiQQmhB7uId6ViUx0b FBTLugcWSb7nuOgTUPItuGiMvwLiJAKMdvUg6Q+86XeDw/NZ70/gY3V+OTfLlorc/LXR 0GCRpKmOksA7V5A0faoFZYoGToXDQ7QrXp+Wv58IPhddcQ9YQLGmDBeNXEj2coqLqCXo tnRfayL+UKzGjgk/toOjBGXCVYwXiH1Fxzq5qUn9+MOUUsqrdWtoGpHQAEK7crK7iSY0 jqHwmNYarfhAji7C0DRV6BfFntorDrxi9MvprCjirlsYoxNvFC8IkIPsXPh9CY9BEUgB 2SuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ehyk8Sp1; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a22-20020aa794b6000000b0064d7336c80dsi1091865pfl.385.2023.05.25.02.59.54; Thu, 25 May 2023 03:00:07 -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=@redhat.com header.s=mimecast20190719 header.b=ehyk8Sp1; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240667AbjEYJxT (ORCPT + 99 others); Thu, 25 May 2023 05:53:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231934AbjEYJxR (ORCPT ); Thu, 25 May 2023 05:53:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81BC2198 for ; Thu, 25 May 2023 02:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685008352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T483GshQ1etV4/B80hSTyHnl4OtRX6eMmZK03OF9d2k=; b=ehyk8Sp1/uG/TGtsGbMfvc3IEZHO6/Hk9LgW+drL7lPwS3jhs9nRpx9iYow/CyL1QMY9Mh ufuvtQlWqh81vNekqi7SelyqZCR1Kq1Lry+lwDCRgMBW0+ENFqYXxPTqjqzN5QKGV/lrb8 awJHfgqtLVV2JD8Jq0pdXDWDuc7bjd0= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-197-SqYuNH8PPeW5TqEEswp41g-1; Thu, 25 May 2023 05:52:31 -0400 X-MC-Unique: SqYuNH8PPeW5TqEEswp41g-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-50dfa390825so2504101a12.3 for ; Thu, 25 May 2023 02:52:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685008349; x=1687600349; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T483GshQ1etV4/B80hSTyHnl4OtRX6eMmZK03OF9d2k=; b=GMY+yKkUohRf3N84GNwnH9O4qVypp8UWoqDV0our0wOrWig28+ag65VXs0A0LLdDeL zSr5HG9wSlMiCvfcnXy2AJcvuQUXtNO1Q1sWCpWKAGiwCp6YE1xBF4zhI7MZJfRAUjC1 9D7fQUdjhTSJpKGypOjXn9WJ6iiR7KRT9pX/gKQ593ofb532Rl78ZW8cpbLC7SXqM2Pz cSkU1gVirsIxRx0QohiututHIn7tPLoMjPR0gH0z68MyTR+2hDEmZ27PkBl5wZpxjUHG 2BCMkPxhyF0A2xDtPXIdwmN8CsWkBQClsKXWonvh2qlTSeiPvkYioTWFhQ0L3qnixxzO A6NQ== X-Gm-Message-State: AC+VfDyvX++WNTbLZ8FQ0sth5LNGRyJr56GBnhlw4Osyk6At0zeaJgDT fdvn5XEMOhPbg9DkYvh2jXt3dma2UfIVujkFYiKs8TmBQgSRJzC5IbIK7Ly3QMNBfXDFp7WzxY+ /4vK2deeUgsf+iMaUqs3VP3FdhhqYxlqe X-Received: by 2002:aa7:d316:0:b0:50b:c72a:2b26 with SMTP id p22-20020aa7d316000000b0050bc72a2b26mr4278277edq.9.1685008349619; Thu, 25 May 2023 02:52:29 -0700 (PDT) X-Received: by 2002:aa7:d316:0:b0:50b:c72a:2b26 with SMTP id p22-20020aa7d316000000b0050bc72a2b26mr4278270edq.9.1685008349312; Thu, 25 May 2023 02:52:29 -0700 (PDT) Received: from ?IPV6:2001:1c00:c32:7800:5bfa:a036:83f0:f9ec? (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id d27-20020a056402517b00b0050c0d651fb1sm377005ede.75.2023.05.25.02.52.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 May 2023 02:52:28 -0700 (PDT) Message-ID: Date: Thu, 25 May 2023 11:52:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH 1/4] platform/x86: think-lmi: Enable opcode support on BIOS settings Content-Language: en-US, nl To: Mark Pearson Cc: "markgross@kernel.org" , "platform-driver-x86@vger.kernel.org" , linux-kernel@vger.kernel.org References: <20230517181945.3725-1-mpearson-lenovo@squebb.ca> <04415f83-64fa-4d70-91fa-4425e163b350@app.fastmail.com> <71d0ddfa-ccca-43ee-aaac-6daf6b876824@app.fastmail.com> From: Hans de Goede In-Reply-To: <71d0ddfa-ccca-43ee-aaac-6daf6b876824@app.fastmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=unavailable 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 Hi Mark, On 5/24/23 20:20, Mark Pearson wrote: > Hi Hans, > > On Tue, May 23, 2023, at 8:36 AM, Mark Pearson wrote: >> Thanks Hans, >> >> On Tue, May 23, 2023, at 6:46 AM, Hans de Goede wrote: >>> Hi Mark, >>> >>> On 5/17/23 20:19, Mark Pearson wrote: >>>> Whilst reviewing some documentation from the FW team on using WMI on >>>> Lenovo system I noticed that we weren't using Opcode support when >>>> changing BIOS settings in the thinkLMI driver. >>>> >>>> We should be doing this to ensure we're future proof as the old >>>> non-opcode mechanism has been deprecated. >>>> >>>> Tested on X1 Carbon G10 and G11. >>>> >>>> Signed-off-by: Mark Pearson >>>> --- >>>> drivers/platform/x86/think-lmi.c | 23 ++++++++++++++++++++++- >>>> 1 file changed, 22 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c >>>> index 1138f770149d..d9341305eba9 100644 >>>> --- a/drivers/platform/x86/think-lmi.c >>>> +++ b/drivers/platform/x86/think-lmi.c >>>> @@ -1001,7 +1001,28 @@ static ssize_t current_value_store(struct kobject *kobj, >>>> tlmi_priv.pwd_admin->save_signature); >>>> if (ret) >>>> goto out; >>> >>>> - } else { /* Non certiifcate based authentication */ >>>> + } else if (tlmi_priv.opcode_support) { >>>> + /* If opcode support is present use that interface */ >>>> + set_str = kasprintf(GFP_KERNEL, "%s,%s;", setting->display_name, >>>> + new_setting); >>>> + if (!set_str) { >>>> + ret = -ENOMEM; >>>> + goto out; >>>> + } >>>> + >>>> + ret = tlmi_simple_call(LENOVO_SET_BIOS_SETTINGS_GUID, set_str); >>>> + if (ret) >>>> + goto out; >>>> + >>>> + if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) { >>>> + ret = tlmi_opcode_setting("WmiOpcodePasswordAdmin", >>>> + tlmi_priv.pwd_admin->password); >>>> + if (ret) >>>> + goto out; >>>> + } >>>> + >>>> + ret = tlmi_save_bios_settings(""); >>> >>> I'm a bit confused about how this works. You are calling the same >>> LENOVO_SET_BIOS_SETTINGS_GUID as the old non opcode based authentication method >>> without any auth string. >>> >>> And then afterwards you are calling LENOVO_OPCODE_IF_GUID with >>> "WmiOpcodePasswordAdmin:" >>> >>> Won't the initial LENOVO_SET_BIOS_SETTINGS_GUID get rejected since >>> it does not include an auth-string and you have not authenticated >>> yet using the opcode mechanism either. IOW shouldn't the opcode >>> auth call go first ? >>> >>> And how does this work timing wise, vs races with userspace doing >>> multiple sysfs writes at once. >>> >>> If the authentication done afterwards really acks the last >>> LENOVO_SET_BIOS_SETTINGS_GUID call then a userspace based >>> attacker could try to race and overwrite the last >>> LENOVO_SET_BIOS_SETTINGS_GUID call before the ack happens... ? >>> >>> If this code really is correct I think we need to introduce >>> a mutex to avoid this race. >>> >>> And this also needs some comments to explain what is going on. >> >> Agreed - and looking at it now....I'm questioning it myself. This was >> tested so it works...but I wonder if that was more luck than judgement. >> Let me do some checking - I think I may have messed up here. >> > > Looked at this and the code is correct - even if it is a bit weird :) > https://docs.lenovocdrt.com/#/bios/wmi/wmi_guide?id=set-and-save-a-bios-setting-on-newer-models > > The save_bios_settings would fail if a password was not set (if it's required). Ok, can you add some comments to the next revision explaining this ? (no need to write a novel, just some short comments) > With regards to race conditions - that does seem somewhat unlikely in real life but I can add a mutex around this to catch that condition. I think I should probably do the same in a couple of other places (e.g. certificate_store and new_password_store) where multiple WMI calls are needed to complete an operation. Ack for also adding the mutex in other places where there is more then 1 WMI call involved. > Is it OK if I do that as a separate commit on the end of the series or would you rather it was included in this commit? As the scope is, I think, more than just this function I'm leaning towards a separate commit but let me know what best practice is. Adding this in a separate commit is fine with me. Regards, Hans