Skip to content

Commit cc9c4f0

Browse files
committed
Merge tag 'for-linus-6.8a-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip
Pull xen fixes from Juergen Gross: "Fixes and simple cleanups: - use a proper flexible array instead of a one-element array in order to avoid array-bounds sanitizer errors - add NULL pointer checks after allocating memory - use memdup_array_user() instead of open-coding it - fix a rare race condition in Xen event channel allocation code - make struct bus_type instances const - make kerneldoc inline comments match reality" * tag 'for-linus-6.8a-rc5-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/xen/tip: xen/events: close evtchn after mapping cleanup xen/gntalloc: Replace UAPI 1-element array xen: balloon: make balloon_subsys const xen: pcpu: make xen_pcpu_subsys const xen/privcmd: Use memdup_array_user() in alloc_ioreq() x86/xen: Add some null pointer checking to smp.c xen/xenbus: document will_handle argument for xenbus_watch_path()
2 parents 68fb3ca + fa765c4 commit cc9c4f0

File tree

8 files changed

+39
-22
lines changed

8 files changed

+39
-22
lines changed

arch/x86/xen/smp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ int xen_smp_intr_init(unsigned int cpu)
6565
char *resched_name, *callfunc_name, *debug_name;
6666

6767
resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu);
68+
if (!resched_name)
69+
goto fail_mem;
6870
per_cpu(xen_resched_irq, cpu).name = resched_name;
6971
rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR,
7072
cpu,
@@ -77,6 +79,8 @@ int xen_smp_intr_init(unsigned int cpu)
7779
per_cpu(xen_resched_irq, cpu).irq = rc;
7880

7981
callfunc_name = kasprintf(GFP_KERNEL, "callfunc%d", cpu);
82+
if (!callfunc_name)
83+
goto fail_mem;
8084
per_cpu(xen_callfunc_irq, cpu).name = callfunc_name;
8185
rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR,
8286
cpu,
@@ -90,6 +94,9 @@ int xen_smp_intr_init(unsigned int cpu)
9094

9195
if (!xen_fifo_events) {
9296
debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu);
97+
if (!debug_name)
98+
goto fail_mem;
99+
93100
per_cpu(xen_debug_irq, cpu).name = debug_name;
94101
rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu,
95102
xen_debug_interrupt,
@@ -101,6 +108,9 @@ int xen_smp_intr_init(unsigned int cpu)
101108
}
102109

103110
callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu);
111+
if (!callfunc_name)
112+
goto fail_mem;
113+
104114
per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name;
105115
rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR,
106116
cpu,
@@ -114,6 +124,8 @@ int xen_smp_intr_init(unsigned int cpu)
114124

115125
return 0;
116126

127+
fail_mem:
128+
rc = -ENOMEM;
117129
fail:
118130
xen_smp_intr_free(cpu);
119131
return rc;

drivers/xen/events/events_base.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,8 @@ static void shutdown_pirq(struct irq_data *data)
923923
return;
924924

925925
do_mask(info, EVT_MASK_REASON_EXPLICIT);
926-
xen_evtchn_close(evtchn);
927926
xen_irq_info_cleanup(info);
927+
xen_evtchn_close(evtchn);
928928
}
929929

930930
static void enable_pirq(struct irq_data *data)
@@ -956,6 +956,7 @@ EXPORT_SYMBOL_GPL(xen_irq_from_gsi);
956956
static void __unbind_from_irq(struct irq_info *info, unsigned int irq)
957957
{
958958
evtchn_port_t evtchn;
959+
bool close_evtchn = false;
959960

960961
if (!info) {
961962
xen_irq_free_desc(irq);
@@ -975,7 +976,7 @@ static void __unbind_from_irq(struct irq_info *info, unsigned int irq)
975976
struct xenbus_device *dev;
976977

977978
if (!info->is_static)
978-
xen_evtchn_close(evtchn);
979+
close_evtchn = true;
979980

980981
switch (info->type) {
981982
case IRQT_VIRQ:
@@ -995,6 +996,9 @@ static void __unbind_from_irq(struct irq_info *info, unsigned int irq)
995996
}
996997

997998
xen_irq_info_cleanup(info);
999+
1000+
if (close_evtchn)
1001+
xen_evtchn_close(evtchn);
9981002
}
9991003

10001004
xen_free_irq(info);

drivers/xen/gntalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static long gntalloc_ioctl_alloc(struct gntalloc_file_private_data *priv,
317317
rc = -EFAULT;
318318
goto out_free;
319319
}
320-
if (copy_to_user(arg->gref_ids, gref_ids,
320+
if (copy_to_user(arg->gref_ids_flex, gref_ids,
321321
sizeof(gref_ids[0]) * op.count)) {
322322
rc = -EFAULT;
323323
goto out_free;

drivers/xen/pcpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct pcpu {
6565
uint32_t flags;
6666
};
6767

68-
static struct bus_type xen_pcpu_subsys = {
68+
static const struct bus_type xen_pcpu_subsys = {
6969
.name = "xen_cpu",
7070
.dev_name = "xen_cpu",
7171
};

drivers/xen/privcmd.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,18 +1223,13 @@ struct privcmd_kernel_ioreq *alloc_ioreq(struct privcmd_ioeventfd *ioeventfd)
12231223
kioreq->ioreq = (struct ioreq *)(page_to_virt(pages[0]));
12241224
mmap_write_unlock(mm);
12251225

1226-
size = sizeof(*ports) * kioreq->vcpus;
1227-
ports = kzalloc(size, GFP_KERNEL);
1228-
if (!ports) {
1229-
ret = -ENOMEM;
1226+
ports = memdup_array_user(u64_to_user_ptr(ioeventfd->ports),
1227+
kioreq->vcpus, sizeof(*ports));
1228+
if (IS_ERR(ports)) {
1229+
ret = PTR_ERR(ports);
12301230
goto error_kfree;
12311231
}
12321232

1233-
if (copy_from_user(ports, u64_to_user_ptr(ioeventfd->ports), size)) {
1234-
ret = -EFAULT;
1235-
goto error_kfree_ports;
1236-
}
1237-
12381233
for (i = 0; i < kioreq->vcpus; i++) {
12391234
kioreq->ports[i].vcpu = i;
12401235
kioreq->ports[i].port = ports[i];
@@ -1256,7 +1251,7 @@ struct privcmd_kernel_ioreq *alloc_ioreq(struct privcmd_ioeventfd *ioeventfd)
12561251
error_unbind:
12571252
while (--i >= 0)
12581253
unbind_from_irqhandler(irq_from_evtchn(ports[i]), &kioreq->ports[i]);
1259-
error_kfree_ports:
1254+
12601255
kfree(ports);
12611256
error_kfree:
12621257
kfree(kioreq);

drivers/xen/xen-balloon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static const struct attribute_group *balloon_groups[] = {
237237
NULL
238238
};
239239

240-
static struct bus_type balloon_subsys = {
240+
static const struct bus_type balloon_subsys = {
241241
.name = BALLOON_CLASS_NAME,
242242
.dev_name = BALLOON_CLASS_NAME,
243243
};

drivers/xen/xenbus/xenbus_client.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,15 @@ EXPORT_SYMBOL_GPL(xenbus_strstate);
116116
* @dev: xenbus device
117117
* @path: path to watch
118118
* @watch: watch to register
119+
* @will_handle: events queuing determine callback
119120
* @callback: callback to register
120121
*
121122
* Register a @watch on the given path, using the given xenbus_watch structure
122-
* for storage, and the given @callback function as the callback. On success,
123-
* the given @path will be saved as @watch->node, and remains the
124-
* caller's to free. On error, @watch->node will
125-
* be NULL, the device will switch to %XenbusStateClosing, and the error will
126-
* be saved in the store.
123+
* for storage, @will_handle function as the callback to determine if each
124+
* event need to be queued, and the given @callback function as the callback.
125+
* On success, the given @path will be saved as @watch->node, and remains the
126+
* caller's to free. On error, @watch->node will be NULL, the device will
127+
* switch to %XenbusStateClosing, and the error will be saved in the store.
127128
*
128129
* Returns: %0 on success or -errno on error
129130
*/
@@ -158,11 +159,13 @@ EXPORT_SYMBOL_GPL(xenbus_watch_path);
158159
* xenbus_watch_pathfmt - register a watch on a sprintf-formatted path
159160
* @dev: xenbus device
160161
* @watch: watch to register
162+
* @will_handle: events queuing determine callback
161163
* @callback: callback to register
162164
* @pathfmt: format of path to watch
163165
*
164166
* Register a watch on the given @path, using the given xenbus_watch
165-
* structure for storage, and the given @callback function as the
167+
* structure for storage, @will_handle function as the callback to determine if
168+
* each event need to be queued, and the given @callback function as the
166169
* callback. On success, the watched path (@path/@path2) will be saved
167170
* as @watch->node, and becomes the caller's to kfree().
168171
* On error, watch->node will be NULL, so the caller has nothing to

include/uapi/xen/gntalloc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ struct ioctl_gntalloc_alloc_gref {
3131
__u64 index;
3232
/* The grant references of the newly created grant, one per page */
3333
/* Variable size, depending on count */
34-
__u32 gref_ids[1];
34+
union {
35+
__u32 gref_ids[1];
36+
__DECLARE_FLEX_ARRAY(__u32, gref_ids_flex);
37+
};
3538
};
3639

3740
#define GNTALLOC_FLAG_WRITABLE 1

0 commit comments

Comments
 (0)