linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvme: Define compat_ioctl again to unbreak 32-bit userspace.
@ 2022-07-20  1:55 Nick Bowler
  2022-07-20  3:51 ` Guixin Liu
  2022-07-20  4:27 ` Christoph Hellwig
  0 siblings, 2 replies; 5+ messages in thread
From: Nick Bowler @ 2022-07-20  1:55 UTC (permalink / raw)
  To: linux-nvme, linux-kernel; +Cc: Christoph Hellwig

Commit 89b3d6e60550 ("nvme: simplify the compat ioctl handling") removed
the initialization of compat_ioctl from the nvme block_device_operations
structures.

Presumably the expectation was that 32-bit ioctls would be directed
through the regular handler but this is not the case: failing to assign
.compat_ioctl actually means that the compat case is disabled entirely,
and any attempt to submit nvme ioctls from 32-bit userspace fails
outright with -ENOTTY.

For example:

  % smartctl -x /dev/nvme0n1
  [...]
  Read NVMe Identify Controller failed: NVME_IOCTL_ADMIN_CMD: Inappropriate ioctl for device

Direct .compat_ioctl to the main ioctl handlers in order to make things
work again.

Fixes: 89b3d6e60550 ("nvme: simplify the compat ioctl handling")
Signed-off-by: Nick Bowler <nbowler@draconx.ca>
---
 drivers/nvme/host/core.c      | 1 +
 drivers/nvme/host/multipath.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index a2862a56fadc..30e105dbc178 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2093,6 +2093,7 @@ static int nvme_report_zones(struct gendisk *disk, sector_t sector,
 static const struct block_device_operations nvme_bdev_ops = {
 	.owner		= THIS_MODULE,
 	.ioctl		= nvme_ioctl,
+	.compat_ioctl	= nvme_ioctl,
 	.open		= nvme_open,
 	.release	= nvme_release,
 	.getgeo		= nvme_getgeo,
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index d464fdf978fb..0f38a5feec22 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -408,6 +408,7 @@ const struct block_device_operations nvme_ns_head_ops = {
 	.open		= nvme_ns_head_open,
 	.release	= nvme_ns_head_release,
 	.ioctl		= nvme_ns_head_ioctl,
+	.compat_ioctl	= nvme_ns_head_ioctl,
 	.getgeo		= nvme_getgeo,
 	.report_zones	= nvme_ns_head_report_zones,
 	.pr_ops		= &nvme_pr_ops,
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvme: Define compat_ioctl again to unbreak 32-bit userspace.
  2022-07-20  1:55 [PATCH] nvme: Define compat_ioctl again to unbreak 32-bit userspace Nick Bowler
@ 2022-07-20  3:51 ` Guixin Liu
  2022-07-21  3:56   ` Nick Bowler
  2022-07-20  4:27 ` Christoph Hellwig
  1 sibling, 1 reply; 5+ messages in thread
From: Guixin Liu @ 2022-07-20  3:51 UTC (permalink / raw)
  To: Nick Bowler, linux-nvme, linux-kernel; +Cc: Christoph Hellwig

Hi Nick,

Should this in the brace of "#ifdef CONFIG_COMPAT" and "#endif"?

best regards,

Guixin Liu

在 2022/7/20 09:55, Nick Bowler 写道:
> Commit 89b3d6e60550 ("nvme: simplify the compat ioctl handling") removed
> the initialization of compat_ioctl from the nvme block_device_operations
> structures.
>
> Presumably the expectation was that 32-bit ioctls would be directed
> through the regular handler but this is not the case: failing to assign
> .compat_ioctl actually means that the compat case is disabled entirely,
> and any attempt to submit nvme ioctls from 32-bit userspace fails
> outright with -ENOTTY.
>
> For example:
>
>    % smartctl -x /dev/nvme0n1
>    [...]
>    Read NVMe Identify Controller failed: NVME_IOCTL_ADMIN_CMD: Inappropriate ioctl for device
>
> Direct .compat_ioctl to the main ioctl handlers in order to make things
> work again.
>
> Fixes: 89b3d6e60550 ("nvme: simplify the compat ioctl handling")
> Signed-off-by: Nick Bowler <nbowler@draconx.ca>
> ---
>   drivers/nvme/host/core.c      | 1 +
>   drivers/nvme/host/multipath.c | 1 +
>   2 files changed, 2 insertions(+)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index a2862a56fadc..30e105dbc178 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2093,6 +2093,7 @@ static int nvme_report_zones(struct gendisk *disk, sector_t sector,
>   static const struct block_device_operations nvme_bdev_ops = {
>   	.owner		= THIS_MODULE,
>   	.ioctl		= nvme_ioctl,
> +	.compat_ioctl	= nvme_ioctl,
>   	.open		= nvme_open,
>   	.release	= nvme_release,
>   	.getgeo		= nvme_getgeo,
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index d464fdf978fb..0f38a5feec22 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -408,6 +408,7 @@ const struct block_device_operations nvme_ns_head_ops = {
>   	.open		= nvme_ns_head_open,
>   	.release	= nvme_ns_head_release,
>   	.ioctl		= nvme_ns_head_ioctl,
> +	.compat_ioctl	= nvme_ns_head_ioctl,
>   	.getgeo		= nvme_getgeo,
>   	.report_zones	= nvme_ns_head_report_zones,
>   	.pr_ops		= &nvme_pr_ops,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvme: Define compat_ioctl again to unbreak 32-bit userspace.
  2022-07-20  1:55 [PATCH] nvme: Define compat_ioctl again to unbreak 32-bit userspace Nick Bowler
  2022-07-20  3:51 ` Guixin Liu
@ 2022-07-20  4:27 ` Christoph Hellwig
  2022-07-20 12:49   ` Nick Bowler
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2022-07-20  4:27 UTC (permalink / raw)
  To: Nick Bowler; +Cc: linux-nvme, linux-kernel, Christoph Hellwig

On Tue, Jul 19, 2022 at 09:55:38PM -0400, Nick Bowler wrote:
> Commit 89b3d6e60550 ("nvme: simplify the compat ioctl handling") removed
> the initialization of compat_ioctl from the nvme block_device_operations
> structures.
> 
> Presumably the expectation was that 32-bit ioctls would be directed
> through the regular handler but this is not the case: failing to assign
> .compat_ioctl actually means that the compat case is disabled entirely,
> and any attempt to submit nvme ioctls from 32-bit userspace fails
> outright with -ENOTTY.

I don't think wiring up the native version is the right thing to do,
this needs to be blkdev_compat_ptr_ioctl, just like we use
compat_ptr_ioctl for the character device nodes.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvme: Define compat_ioctl again to unbreak 32-bit userspace.
  2022-07-20  4:27 ` Christoph Hellwig
@ 2022-07-20 12:49   ` Nick Bowler
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Bowler @ 2022-07-20 12:49 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-nvme, linux-kernel

On 2022-07-20, Christoph Hellwig <hch@lst.de> wrote:
> On Tue, Jul 19, 2022 at 09:55:38PM -0400, Nick Bowler wrote:
>> Commit 89b3d6e60550 ("nvme: simplify the compat ioctl handling") removed
>> the initialization of compat_ioctl from the nvme block_device_operations
>> structures.
>>
>> Presumably the expectation was that 32-bit ioctls would be directed
>> through the regular handler but this is not the case: failing to assign
>> .compat_ioctl actually means that the compat case is disabled entirely,
>> and any attempt to submit nvme ioctls from 32-bit userspace fails
>> outright with -ENOTTY.
>
> I don't think wiring up the native version is the right thing to do,
> this needs to be blkdev_compat_ptr_ioctl, just like we use
> compat_ptr_ioctl for the character device nodes.

OK, I will try that.

Thanks,
  Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvme: Define compat_ioctl again to unbreak 32-bit userspace.
  2022-07-20  3:51 ` Guixin Liu
@ 2022-07-21  3:56   ` Nick Bowler
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Bowler @ 2022-07-21  3:56 UTC (permalink / raw)
  To: Guixin Liu; +Cc: linux-nvme, linux-kernel, Christoph Hellwig

On 2022-07-19, Guixin Liu <kanie@linux.alibaba.com> wrote:
> 在 2022/7/20 09:55, Nick Bowler 写道:
[...]
>> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
>> index a2862a56fadc..30e105dbc178 100644
>> --- a/drivers/nvme/host/core.c
>> +++ b/drivers/nvme/host/core.c
>> @@ -2093,6 +2093,7 @@ static int nvme_report_zones(struct gendisk *disk,
>> sector_t sector,
>>   static const struct block_device_operations nvme_bdev_ops = {
>>   	.owner		= THIS_MODULE,
>>   	.ioctl		= nvme_ioctl,
>> +	.compat_ioctl	= nvme_ioctl,
>>   	.open		= nvme_open,
>>   	.release	= nvme_release,
>>   	.getgeo		= nvme_getgeo,
[...]
> Should this in the brace of "#ifdef CONFIG_COMPAT" and "#endif"?

I think it doesn't make any significant difference either way -- the
.compat_ioctl member is always present in the block_device_operations
structure.  Unconditional assignment thus seems more sensible to me.

v2 uses blkdev_compat_ptr_ioctl which expands to NULL for !CONFIG_COMPAT.

Thanks,
  Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-07-21  3:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-20  1:55 [PATCH] nvme: Define compat_ioctl again to unbreak 32-bit userspace Nick Bowler
2022-07-20  3:51 ` Guixin Liu
2022-07-21  3:56   ` Nick Bowler
2022-07-20  4:27 ` Christoph Hellwig
2022-07-20 12:49   ` Nick Bowler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).