mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Moyer <jmoyer@redhat.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: linux-nvdimm <linux-nvdimm@lists.01.org>,
	stable <stable@vger.kernel.org>,
	stuart hayes <stuart.w.hayes@gmail.com>,
	Sujith Pandel <sujith_pandel@dell.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 0/2] acpi/nfit: Fix command-supported detection
Date: Tue, 15 Jan 2019 15:39:13 -0500	[thread overview]
Message-ID: <x49k1j57j0u.fsf@segfault.boston.devel.redhat.com> (raw)
In-Reply-To: <CAPcyv4htfew=7D_B1QDGTwSkMTx7BK2BZ+Gq+9UL1NTtqtL9FQ@mail.gmail.com> (Dan Williams's message of "Tue, 15 Jan 2019 08:48:18 -0800")

Dan Williams <dan.j.williams@intel.com> writes:

> On Tue, Jan 15, 2019 at 6:16 AM Jeff Moyer <jmoyer@redhat.com> wrote:
>>
>> Dan Williams <dan.j.williams@intel.com> writes:
>>
>> > Changes since v1 [1]:
>> > * Include another patch make sure that function-number zero can be
>> >   safely used as an invalid function number (Jeff)
>> > * Add a comment clarifying why zero is an invalid function number (Jeff)
>> > * Pass nfit_mem to cmd_to_func() (Jeff)
>> > * Collect a Tested-by from Sujith
>> > [1]: https://lists.01.org/pipermail/linux-nvdimm/2019-January/019435.html
>>
>> For the series:
>>
>> Reviewed-by: Jeff Moyer <jmoyer@redhat.com>
>>
>> Thanks, Dan!
>
> Thanks, although I just realized one more change. The ND_CMD_CALL case
> should zero out command after the function translation, otherwise
> userspace can call functions that the kernel is blocking in the
> dsm_mask.
>
> Holler if this invalidates your "Reviewed-by".

AAAAAAAHHHHHHHHHH!!!!

:)

> diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
> index 87e02f281e51..d7747aceb7ab 100644
> --- a/drivers/acpi/nfit/core.c
> +++ b/drivers/acpi/nfit/core.c
> @@ -463,6 +463,12 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor
> *nd_desc, struct nvdimm *nvdimm,
>                 func = cmd_to_func(nfit_mem, cmd, buf);
>                 if (func < 0)
>                         return func;
> +               /*
> +                * In the ND_CMD_CALL case we're now dependent on 'func'
> +                * being validated by the dimm's dsm_mask
> +                */
> +               if (cmd == ND_CMD_CALL)
> +                       cmd = 0;
>                 dimm_name = nvdimm_name(nvdimm);
>                 cmd_name = nvdimm_cmd_name(cmd);
>                 cmd_mask = nvdimm_cmd_mask(nvdimm);
                dsm_mask = nfit_mem->dsm_mask;
                desc = nd_cmd_dimm_desc(cmd);

That sure doesn't look right.  Now cmd_name and desc will be wrong.

> @@ -477,8 +483,10 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor
> *nd_desc, struct nvdimm *nvdimm,
>                 cmd_name = nvdimm_bus_cmd_name(cmd);
>                 cmd_mask = nd_desc->cmd_mask;
>                 dsm_mask = cmd_mask;
> -               if (cmd == ND_CMD_CALL)
> +               if (cmd == ND_CMD_CALL) {
>                         dsm_mask = nd_desc->bus_dsm_mask;
> +                       cmd = 0;
> +               }
>                 desc = nd_cmd_bus_desc(cmd);

And again here.

We could reorder the zeroing, or you could modify the check for a valid
comand/function.  Something like this?

	/*
         * Check for a valid command.  For ND_CMD_CALL, we also
         * have to make sure that the DSM function is supported.
         */
	if (cmd == ND_CMD_CALL && !test_bit(func, &dsm_mask))
        	return -ENOTTY;
	else if (!test_bit(cmd, &cmd_mask))
		return -ENOTTY;

Which way do you think is cleaner?

Cheers,
Jeff

  reply	other threads:[~2019-01-15 20:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15  1:57 Dan Williams
2019-01-15  1:57 ` [PATCH v2 1/2] acpi/nfit: Block function zero DSMs Dan Williams
2019-01-15  1:57 ` [PATCH v2 2/2] acpi/nfit: Fix command-supported detection Dan Williams
2019-01-15 14:16 ` [PATCH v2 0/2] " Jeff Moyer
2019-01-15 16:48   ` Dan Williams
2019-01-15 20:39     ` Jeff Moyer [this message]
2019-01-15 21:04       ` Dan Williams

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=x49k1j57j0u.fsf@segfault.boston.devel.redhat.com \
    --to=jmoyer@redhat.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=stable@vger.kernel.org \
    --cc=stuart.w.hayes@gmail.com \
    --cc=sujith_pandel@dell.com \
    --cc=vishal.l.verma@intel.com \
    /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

all inboxes | Powered by JetHome®