Skip to content

Commit 3d25b1e

Browse files
committed
Merge tag 'nvme-6.2-2023-01-12' of git://git.infradead.org/nvme into block-6.2
Pull NVMe fixes from Christoph: "nvme fixes for Linux 6.2 - Identify quirks for Apple controllers (Hector Martin) - fix error handling in nvme_pci_enable (Tong Zhang) - refuse unprivileged passthrough on partitions (Christoph Hellwig) - fix MAINTAINERS to not match nvmem subsystem headers (Russell King)" * tag 'nvme-6.2-2023-01-12' of git://git.infradead.org/nvme: MAINTAINERS: stop nvme matching for nvmem files nvme: don't allow unprivileged passthrough on partitions nvme: replace the "bool vec" arguments with flags in the ioctl path nvme: remove __nvme_ioctl nvme-pci: fix error handling in nvme_pci_enable() nvme-pci: add NVME_QUIRK_IDENTIFY_CNS quirk to Apple T2 controllers nvme-apple: add NVME_QUIRK_IDENTIFY_CNS quirk to fix regression
2 parents 49e4d04 + c7c0644 commit 3d25b1e

File tree

4 files changed

+75
-52
lines changed

4 files changed

+75
-52
lines changed

MAINTAINERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14830,7 +14830,8 @@ T: git://git.infradead.org/nvme.git
1483014830
F: Documentation/nvme/
1483114831
F: drivers/nvme/host/
1483214832
F: drivers/nvme/common/
14833-
F: include/linux/nvme*
14833+
F: include/linux/nvme.h
14834+
F: include/linux/nvme-*.h
1483414835
F: include/uapi/linux/nvme_ioctl.h
1483514836

1483614837
NVM EXPRESS FABRICS AUTHENTICATION

drivers/nvme/host/apple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ static int apple_nvme_probe(struct platform_device *pdev)
14931493
}
14941494

14951495
ret = nvme_init_ctrl(&anv->ctrl, anv->dev, &nvme_ctrl_ops,
1496-
NVME_QUIRK_SKIP_CID_GEN);
1496+
NVME_QUIRK_SKIP_CID_GEN | NVME_QUIRK_IDENTIFY_CNS);
14971497
if (ret) {
14981498
dev_err_probe(dev, ret, "Failed to initialize nvme_ctrl");
14991499
goto put_dev;

drivers/nvme/host/ioctl.c

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@
88
#include <linux/io_uring.h>
99
#include "nvme.h"
1010

11+
enum {
12+
NVME_IOCTL_VEC = (1 << 0),
13+
NVME_IOCTL_PARTITION = (1 << 1),
14+
};
15+
1116
static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c,
12-
fmode_t mode)
17+
unsigned int flags, fmode_t mode)
1318
{
1419
u32 effects;
1520

1621
if (capable(CAP_SYS_ADMIN))
1722
return true;
1823

24+
/*
25+
* Do not allow unprivileged passthrough on partitions, as that allows an
26+
* escape from the containment of the partition.
27+
*/
28+
if (flags & NVME_IOCTL_PARTITION)
29+
return false;
30+
1931
/*
2032
* Do not allow unprivileged processes to send vendor specific or fabrics
2133
* commands as we can't be sure about their effects.
@@ -150,7 +162,7 @@ static struct request *nvme_alloc_user_request(struct request_queue *q,
150162
static int nvme_map_user_request(struct request *req, u64 ubuffer,
151163
unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
152164
u32 meta_seed, void **metap, struct io_uring_cmd *ioucmd,
153-
bool vec)
165+
unsigned int flags)
154166
{
155167
struct request_queue *q = req->q;
156168
struct nvme_ns *ns = q->queuedata;
@@ -163,7 +175,7 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
163175
struct iov_iter iter;
164176

165177
/* fixedbufs is only for non-vectored io */
166-
if (WARN_ON_ONCE(vec))
178+
if (WARN_ON_ONCE(flags & NVME_IOCTL_VEC))
167179
return -EINVAL;
168180
ret = io_uring_cmd_import_fixed(ubuffer, bufflen,
169181
rq_data_dir(req), &iter, ioucmd);
@@ -172,8 +184,8 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
172184
ret = blk_rq_map_user_iov(q, req, NULL, &iter, GFP_KERNEL);
173185
} else {
174186
ret = blk_rq_map_user_io(req, NULL, nvme_to_user_ptr(ubuffer),
175-
bufflen, GFP_KERNEL, vec, 0, 0,
176-
rq_data_dir(req));
187+
bufflen, GFP_KERNEL, flags & NVME_IOCTL_VEC, 0,
188+
0, rq_data_dir(req));
177189
}
178190

179191
if (ret)
@@ -203,9 +215,9 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
203215
}
204216

205217
static int nvme_submit_user_cmd(struct request_queue *q,
206-
struct nvme_command *cmd, u64 ubuffer,
207-
unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
208-
u32 meta_seed, u64 *result, unsigned timeout, bool vec)
218+
struct nvme_command *cmd, u64 ubuffer, unsigned bufflen,
219+
void __user *meta_buffer, unsigned meta_len, u32 meta_seed,
220+
u64 *result, unsigned timeout, unsigned int flags)
209221
{
210222
struct nvme_ctrl *ctrl;
211223
struct request *req;
@@ -221,7 +233,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
221233
req->timeout = timeout;
222234
if (ubuffer && bufflen) {
223235
ret = nvme_map_user_request(req, ubuffer, bufflen, meta_buffer,
224-
meta_len, meta_seed, &meta, NULL, vec);
236+
meta_len, meta_seed, &meta, NULL, flags);
225237
if (ret)
226238
return ret;
227239
}
@@ -304,10 +316,8 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
304316
c.rw.apptag = cpu_to_le16(io.apptag);
305317
c.rw.appmask = cpu_to_le16(io.appmask);
306318

307-
return nvme_submit_user_cmd(ns->queue, &c,
308-
io.addr, length,
309-
metadata, meta_len, lower_32_bits(io.slba), NULL, 0,
310-
false);
319+
return nvme_submit_user_cmd(ns->queue, &c, io.addr, length, metadata,
320+
meta_len, lower_32_bits(io.slba), NULL, 0, 0);
311321
}
312322

313323
static bool nvme_validate_passthru_nsid(struct nvme_ctrl *ctrl,
@@ -325,7 +335,8 @@ static bool nvme_validate_passthru_nsid(struct nvme_ctrl *ctrl,
325335
}
326336

327337
static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
328-
struct nvme_passthru_cmd __user *ucmd, fmode_t mode)
338+
struct nvme_passthru_cmd __user *ucmd, unsigned int flags,
339+
fmode_t mode)
329340
{
330341
struct nvme_passthru_cmd cmd;
331342
struct nvme_command c;
@@ -353,16 +364,15 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
353364
c.common.cdw14 = cpu_to_le32(cmd.cdw14);
354365
c.common.cdw15 = cpu_to_le32(cmd.cdw15);
355366

356-
if (!nvme_cmd_allowed(ns, &c, mode))
367+
if (!nvme_cmd_allowed(ns, &c, 0, mode))
357368
return -EACCES;
358369

359370
if (cmd.timeout_ms)
360371
timeout = msecs_to_jiffies(cmd.timeout_ms);
361372

362373
status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
363-
cmd.addr, cmd.data_len,
364-
nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
365-
0, &result, timeout, false);
374+
cmd.addr, cmd.data_len, nvme_to_user_ptr(cmd.metadata),
375+
cmd.metadata_len, 0, &result, timeout, 0);
366376

367377
if (status >= 0) {
368378
if (put_user(result, &ucmd->result))
@@ -373,8 +383,8 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
373383
}
374384

375385
static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
376-
struct nvme_passthru_cmd64 __user *ucmd, bool vec,
377-
fmode_t mode)
386+
struct nvme_passthru_cmd64 __user *ucmd, unsigned int flags,
387+
fmode_t mode)
378388
{
379389
struct nvme_passthru_cmd64 cmd;
380390
struct nvme_command c;
@@ -401,16 +411,15 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
401411
c.common.cdw14 = cpu_to_le32(cmd.cdw14);
402412
c.common.cdw15 = cpu_to_le32(cmd.cdw15);
403413

404-
if (!nvme_cmd_allowed(ns, &c, mode))
414+
if (!nvme_cmd_allowed(ns, &c, flags, mode))
405415
return -EACCES;
406416

407417
if (cmd.timeout_ms)
408418
timeout = msecs_to_jiffies(cmd.timeout_ms);
409419

410420
status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
411-
cmd.addr, cmd.data_len,
412-
nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
413-
0, &cmd.result, timeout, vec);
421+
cmd.addr, cmd.data_len, nvme_to_user_ptr(cmd.metadata),
422+
cmd.metadata_len, 0, &cmd.result, timeout, flags);
414423

415424
if (status >= 0) {
416425
if (put_user(cmd.result, &ucmd->result))
@@ -571,7 +580,7 @@ static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
571580
c.common.cdw14 = cpu_to_le32(READ_ONCE(cmd->cdw14));
572581
c.common.cdw15 = cpu_to_le32(READ_ONCE(cmd->cdw15));
573582

574-
if (!nvme_cmd_allowed(ns, &c, ioucmd->file->f_mode))
583+
if (!nvme_cmd_allowed(ns, &c, 0, ioucmd->file->f_mode))
575584
return -EACCES;
576585

577586
d.metadata = READ_ONCE(cmd->metadata);
@@ -641,9 +650,9 @@ static int nvme_ctrl_ioctl(struct nvme_ctrl *ctrl, unsigned int cmd,
641650
{
642651
switch (cmd) {
643652
case NVME_IOCTL_ADMIN_CMD:
644-
return nvme_user_cmd(ctrl, NULL, argp, mode);
653+
return nvme_user_cmd(ctrl, NULL, argp, 0, mode);
645654
case NVME_IOCTL_ADMIN64_CMD:
646-
return nvme_user_cmd64(ctrl, NULL, argp, false, mode);
655+
return nvme_user_cmd64(ctrl, NULL, argp, 0, mode);
647656
default:
648657
return sed_ioctl(ctrl->opal_dev, cmd, argp);
649658
}
@@ -668,14 +677,14 @@ struct nvme_user_io32 {
668677
#endif /* COMPAT_FOR_U64_ALIGNMENT */
669678

670679
static int nvme_ns_ioctl(struct nvme_ns *ns, unsigned int cmd,
671-
void __user *argp, fmode_t mode)
680+
void __user *argp, unsigned int flags, fmode_t mode)
672681
{
673682
switch (cmd) {
674683
case NVME_IOCTL_ID:
675684
force_successful_syscall_return();
676685
return ns->head->ns_id;
677686
case NVME_IOCTL_IO_CMD:
678-
return nvme_user_cmd(ns->ctrl, ns, argp, mode);
687+
return nvme_user_cmd(ns->ctrl, ns, argp, flags, mode);
679688
/*
680689
* struct nvme_user_io can have different padding on some 32-bit ABIs.
681690
* Just accept the compat version as all fields that are used are the
@@ -686,37 +695,40 @@ static int nvme_ns_ioctl(struct nvme_ns *ns, unsigned int cmd,
686695
#endif
687696
case NVME_IOCTL_SUBMIT_IO:
688697
return nvme_submit_io(ns, argp);
689-
case NVME_IOCTL_IO64_CMD:
690-
return nvme_user_cmd64(ns->ctrl, ns, argp, false, mode);
691698
case NVME_IOCTL_IO64_CMD_VEC:
692-
return nvme_user_cmd64(ns->ctrl, ns, argp, true, mode);
699+
flags |= NVME_IOCTL_VEC;
700+
fallthrough;
701+
case NVME_IOCTL_IO64_CMD:
702+
return nvme_user_cmd64(ns->ctrl, ns, argp, flags, mode);
693703
default:
694704
return -ENOTTY;
695705
}
696706
}
697707

698-
static int __nvme_ioctl(struct nvme_ns *ns, unsigned int cmd, void __user *arg,
699-
fmode_t mode)
700-
{
701-
if (is_ctrl_ioctl(cmd))
702-
return nvme_ctrl_ioctl(ns->ctrl, cmd, arg, mode);
703-
return nvme_ns_ioctl(ns, cmd, arg, mode);
704-
}
705-
706708
int nvme_ioctl(struct block_device *bdev, fmode_t mode,
707709
unsigned int cmd, unsigned long arg)
708710
{
709711
struct nvme_ns *ns = bdev->bd_disk->private_data;
712+
void __user *argp = (void __user *)arg;
713+
unsigned int flags = 0;
710714

711-
return __nvme_ioctl(ns, cmd, (void __user *)arg, mode);
715+
if (bdev_is_partition(bdev))
716+
flags |= NVME_IOCTL_PARTITION;
717+
718+
if (is_ctrl_ioctl(cmd))
719+
return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, mode);
720+
return nvme_ns_ioctl(ns, cmd, argp, flags, mode);
712721
}
713722

714723
long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
715724
{
716725
struct nvme_ns *ns =
717726
container_of(file_inode(file)->i_cdev, struct nvme_ns, cdev);
727+
void __user *argp = (void __user *)arg;
718728

719-
return __nvme_ioctl(ns, cmd, (void __user *)arg, file->f_mode);
729+
if (is_ctrl_ioctl(cmd))
730+
return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, file->f_mode);
731+
return nvme_ns_ioctl(ns, cmd, argp, 0, file->f_mode);
720732
}
721733

722734
static int nvme_uring_cmd_checks(unsigned int issue_flags)
@@ -806,6 +818,10 @@ int nvme_ns_head_ioctl(struct block_device *bdev, fmode_t mode,
806818
void __user *argp = (void __user *)arg;
807819
struct nvme_ns *ns;
808820
int srcu_idx, ret = -EWOULDBLOCK;
821+
unsigned int flags = 0;
822+
823+
if (bdev_is_partition(bdev))
824+
flags |= NVME_IOCTL_PARTITION;
809825

810826
srcu_idx = srcu_read_lock(&head->srcu);
811827
ns = nvme_find_path(head);
@@ -821,7 +837,7 @@ int nvme_ns_head_ioctl(struct block_device *bdev, fmode_t mode,
821837
return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx,
822838
mode);
823839

824-
ret = nvme_ns_ioctl(ns, cmd, argp, mode);
840+
ret = nvme_ns_ioctl(ns, cmd, argp, flags, mode);
825841
out_unlock:
826842
srcu_read_unlock(&head->srcu, srcu_idx);
827843
return ret;
@@ -846,7 +862,7 @@ long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd,
846862
return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx,
847863
file->f_mode);
848864

849-
ret = nvme_ns_ioctl(ns, cmd, argp, file->f_mode);
865+
ret = nvme_ns_ioctl(ns, cmd, argp, 0, file->f_mode);
850866
out_unlock:
851867
srcu_read_unlock(&head->srcu, srcu_idx);
852868
return ret;
@@ -945,7 +961,7 @@ static int nvme_dev_user_cmd(struct nvme_ctrl *ctrl, void __user *argp,
945961
kref_get(&ns->kref);
946962
up_read(&ctrl->namespaces_rwsem);
947963

948-
ret = nvme_user_cmd(ctrl, ns, argp, mode);
964+
ret = nvme_user_cmd(ctrl, ns, argp, 0, mode);
949965
nvme_put_ns(ns);
950966
return ret;
951967

@@ -962,9 +978,9 @@ long nvme_dev_ioctl(struct file *file, unsigned int cmd,
962978

963979
switch (cmd) {
964980
case NVME_IOCTL_ADMIN_CMD:
965-
return nvme_user_cmd(ctrl, NULL, argp, file->f_mode);
981+
return nvme_user_cmd(ctrl, NULL, argp, 0, file->f_mode);
966982
case NVME_IOCTL_ADMIN64_CMD:
967-
return nvme_user_cmd64(ctrl, NULL, argp, false, file->f_mode);
983+
return nvme_user_cmd64(ctrl, NULL, argp, 0, file->f_mode);
968984
case NVME_IOCTL_IO_CMD:
969985
return nvme_dev_user_cmd(ctrl, argp, file->f_mode);
970986
case NVME_IOCTL_RESET:

drivers/nvme/host/pci.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ static int nvme_pci_enable(struct nvme_dev *dev)
25332533
*/
25342534
result = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
25352535
if (result < 0)
2536-
return result;
2536+
goto disable;
25372537

25382538
dev->ctrl.cap = lo_hi_readq(dev->bar + NVME_REG_CAP);
25392539

@@ -2586,8 +2586,13 @@ static int nvme_pci_enable(struct nvme_dev *dev)
25862586
pci_enable_pcie_error_reporting(pdev);
25872587
pci_save_state(pdev);
25882588

2589-
return nvme_pci_configure_admin_queue(dev);
2589+
result = nvme_pci_configure_admin_queue(dev);
2590+
if (result)
2591+
goto free_irq;
2592+
return result;
25902593

2594+
free_irq:
2595+
pci_free_irq_vectors(pdev);
25912596
disable:
25922597
pci_disable_device(pdev);
25932598
return result;
@@ -3495,7 +3500,8 @@ static const struct pci_device_id nvme_id_table[] = {
34953500
.driver_data = NVME_QUIRK_SINGLE_VECTOR |
34963501
NVME_QUIRK_128_BYTES_SQES |
34973502
NVME_QUIRK_SHARED_TAGS |
3498-
NVME_QUIRK_SKIP_CID_GEN },
3503+
NVME_QUIRK_SKIP_CID_GEN |
3504+
NVME_QUIRK_IDENTIFY_CNS },
34993505
{ PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_EXPRESS, 0xffffff) },
35003506
{ 0, }
35013507
};

0 commit comments

Comments
 (0)