X86 platform drivers
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali.rohar@gmail.com>
To: Mario Limonciello <mario.limonciello@dell.com>
Cc: dvhart@infradead.org, Andy Shevchenko <andy.shevchenko@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	platform-driver-x86@vger.kernel.org,
	Andy Lutomirski <luto@kernel.org>,
	quasisec@google.com, rjw@rjwysocki.net, mjg59@google.com,
	hch@lst.de, Greg KH <greg@kroah.com>,
	Alan Cox <gnomes@lxorguk.ukuu.org.uk>
Subject: Re: [PATCH v12 10/16] platform/x86: dell-smbios: Introduce dispatcher for SMM calls
Date: Sat, 27 Jan 2018 15:48:23 +0100	[thread overview]
Message-ID: <20180127144823.innndhmtaus3k7op@pali> (raw)
In-Reply-To: <19848e4dec380f91efd1536bbfad092050d232d2.1509561822.git.mario.limonciello@dell.com>

[-- Attachment #1: Type: text/plain, Size: 3768 bytes --]

Hi!

On Wednesday 01 November 2017 14:25:31 Mario Limonciello wrote:
> This splits up the dell-smbios driver into two drivers:
> * dell-smbios
> * dell-smbios-smm
> 
> dell-smbios can operate with multiple different dispatcher drivers to
> perform SMBIOS operations.
> 
> Also modify the interface that dell-laptop and dell-wmi use align to this
> model more closely.  Rather than a single global buffer being allocated
> for all drivers, each driver will allocate and be responsible for it's own
> buffer. The pointer will be passed to the calling function and each
> dispatcher driver will then internally copy it to the proper location to
> perform it's call.
> 
> Add defines for calls used by these methods in the dell-smbios.h header
> for tracking purposes.
> 
> Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
> Reviewed-by: Edward O'Callaghan <quasisec@google.com>
> ---
...
> @@ -85,6 +73,7 @@ static struct platform_driver platform_driver = {
>  	}
>  };
>  
> +static struct calling_interface_buffer *buffer;
>  static struct platform_device *platform_device;
>  static struct backlight_device *dell_backlight_device;
>  static struct rfkill *wifi_rfkill;
> @@ -283,6 +272,27 @@ static const struct dmi_system_id dell_quirks[] __initconst = {
>  	{ }
>  };
>  
> +void dell_set_arguments(u32 arg0, u32 arg1, u32 arg2, u32 arg3)
> +{
> +	memset(buffer, 0, sizeof(struct calling_interface_buffer));
> +	buffer->input[0] = arg0;
> +	buffer->input[1] = arg1;
> +	buffer->input[2] = arg2;
> +	buffer->input[3] = arg3;
> +}
> +
> +int dell_send_request(u16 class, u16 select)
> +{
> +	int ret;
> +
> +	buffer->cmd_class = class;
> +	buffer->cmd_select = select;
> +	ret = dell_smbios_call(buffer);
> +	if (ret != 0)
> +		return ret;
> +	return dell_smbios_error(buffer->output[0]);
> +}
> +
>  /*
>   * Derived from information in smbios-wireless-ctl:
>   *
...
> @@ -413,20 +422,16 @@ static int dell_rfkill_set(void *data, bool blocked)
>  	int status;
>  	int ret;
>  
> -	buffer = dell_smbios_get_buffer();
> -
> -	dell_smbios_send_request(17, 11);
> -	ret = buffer->output[0];
> +	dell_set_arguments(0, 0, 0, 0);
> +	ret = dell_send_request(CLASS_INFO, SELECT_RFKILL);
> +	if (ret)
> +		return ret;
>  	status = buffer->output[1];

Now I'm looking at this patch again and I think it introduced a new race
condition.

Prior this patch, dell_smbios_get_buffer() acquired mutex and returned
pointer to buffer which caller used and then released.

Now buffer is allocated at module load time and is shared for all
functions in this module. And hen is used, there is no mutex protection
for it.

First call is to dell_set_arguments() which modifies that shared buffer
and then dell_send_request() is used to modify and pass buffer to
another function dell_smbios_call().

And function below dell_update_rfkill() is called work queue which also
modifies buffer by dell_set_arguments() function.

Therefore it looks like when dell_update_rfkill() is scheduled at the
same time as dell_rfkill_set() is executed, then both functions
overwrite one shared buffer and something unexpected would be sent to
SMM.

> @@ -613,46 +596,36 @@ static const struct file_operations dell_debugfs_fops = {
>  
>  static void dell_update_rfkill(struct work_struct *ignored)
>  {
> -	struct calling_interface_buffer *buffer;
>  	int hwswitch = 0;
>  	int status;
>  	int ret;
>  
> -	buffer = dell_smbios_get_buffer();
> -
> -	dell_smbios_send_request(17, 11);
> -	ret = buffer->output[0];
> +	dell_set_arguments(0, 0, 0, 0);
> +	ret = dell_send_request(CLASS_INFO, SELECT_RFKILL);
>  	status = buffer->output[1];

-- 
Pali Rohár
pali.rohar@gmail.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2018-01-27 14:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-01 19:25 [PATCH v12 00/16] Introduce support for Dell SMBIOS over WMI Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 01/16] platform/x86: dell-smbios: Prefix class/select with cmd_ Mario Limonciello
2017-11-02  0:30   ` Edward O'Callaghan
2017-11-01 19:25 ` [PATCH v12 02/16] platform/x86: wmi: Add new method wmidev_evaluate_method Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 03/16] platform/x86: dell-wmi: increase severity of some failures Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 04/16] platform/x86: dell-wmi: clean up wmi descriptor check Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 05/16] platform/x86: dell-wmi: don't check length returned Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 06/16] platform/x86: dell-wmi-descriptor: split WMI descriptor into it's own driver Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 07/16] platform/x86: wmi: Don't allow drivers to get each other's GUIDs Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 08/16] platform/x86: dell-smbios: only run if proper oem string is detected Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 09/16] platform/x86: dell-smbios: Add a sysfs interface for SMBIOS tokens Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 10/16] platform/x86: dell-smbios: Introduce dispatcher for SMM calls Mario Limonciello
2018-01-27 14:48   ` Pali Rohár [this message]
2017-11-01 19:25 ` [PATCH v12 11/16] platform/x86: dell-smbios-wmi: Add new WMI dispatcher driver Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 12/16] platform/x86: dell-smbios-smm: test for WSMT Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 13/16] platform/x86: dell-smbios: Add filtering support Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 14/16] platform/x86: wmi: create userspace interface for drivers Mario Limonciello
2017-11-02  0:31   ` Edward O'Callaghan
2017-11-01 19:25 ` [PATCH v12 15/16] platform/x86: dell-smbios-wmi: introduce userspace interface Mario Limonciello
2017-11-01 19:25 ` [PATCH v12 16/16] tools/wmi: add a sample for dell smbios communication over WMI Mario Limonciello
2017-11-03  0:50 ` [PATCH v12 00/16] Introduce support for Dell SMBIOS " Darren Hart
2017-11-03 16:30   ` Mario.Limonciello
2017-11-03 21:00     ` Darren Hart
2017-11-03 21:02       ` Mario.Limonciello

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180127144823.innndhmtaus3k7op@pali \
    --to=pali.rohar@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=dvhart@infradead.org \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=greg@kroah.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mario.limonciello@dell.com \
    --cc=mjg59@google.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=quasisec@google.com \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox