aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshutosh Dixit <ashutosh.dixit@intel.com>2013-11-27 11:58:41 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-27 14:03:38 -0500
commit1e31aa9270daab40c7aef9d5488982e3475b87ef (patch)
treeb1c30376de230c4b21965622c5fc4e2705188ac5
parent286c24028c7f2df637323e672d9aa54a07b67bde (diff)
misc: mic: Fix user space namespace pollution from mic_common.h.
Avoid declaring ALIGN() and __aligned() in include/uapi/linux/mic_common.h since they pollute user space namespace. Also, mic_aligned_size() can be simply replaced simply by sizeof() since all structures where mic_aligned_size() is used are declared using __attribute__ ((aligned(8))); -- >From mail from H Peter Anvin about this: On Fri, Nov 08, 2013 H Peter Anvin <h.peter.anvin@intel.com> wrote: Subject: Namespace pollution in mic_common.h This puts two macros, ALIGN() and __aligned(), into arbitrary user space namespace. This really isn't safe or acceptable, especially since those symbols are highly generic. ... When these structures are forced-aligned, they will in fact have padding automatically added by the compiler to an 8-byte boundary anyway, so mic_aligned_size() does nothing. ... Reported-by: H Peter Anvin <h.peter.anvin@intel.com> Reviewed-by: Sudeep Dutt <sudeep.dutt@intel.com> Signed-off-by: Nikhil Rao <nikhil.rao@intel.com> Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--Documentation/mic/mpssd/mpssd.c4
-rw-r--r--drivers/misc/mic/card/mic_virtio.c4
-rw-r--r--drivers/misc/mic/card/mic_virtio.h7
-rw-r--r--drivers/misc/mic/host/mic_virtio.c2
-rw-r--r--include/uapi/linux/mic_common.h26
5 files changed, 17 insertions, 26 deletions
diff --git a/Documentation/mic/mpssd/mpssd.c b/Documentation/mic/mpssd/mpssd.c
index 5c7fdda56f0e..91f9e8e4ef7b 100644
--- a/Documentation/mic/mpssd/mpssd.c
+++ b/Documentation/mic/mpssd/mpssd.c
@@ -313,7 +313,7 @@ static struct mic_device_desc *get_device_desc(struct mic_info *mic, int type)
313 int i; 313 int i;
314 void *dp = get_dp(mic, type); 314 void *dp = get_dp(mic, type);
315 315
316 for (i = mic_aligned_size(struct mic_bootparam); i < PAGE_SIZE; 316 for (i = sizeof(struct mic_bootparam); i < PAGE_SIZE;
317 i += mic_total_desc_size(d)) { 317 i += mic_total_desc_size(d)) {
318 d = dp + i; 318 d = dp + i;
319 319
@@ -520,7 +520,7 @@ static void *
520virtio_net(void *arg) 520virtio_net(void *arg)
521{ 521{
522 static __u8 vnet_hdr[2][sizeof(struct virtio_net_hdr)]; 522 static __u8 vnet_hdr[2][sizeof(struct virtio_net_hdr)];
523 static __u8 vnet_buf[2][MAX_NET_PKT_SIZE] __aligned(64); 523 static __u8 vnet_buf[2][MAX_NET_PKT_SIZE] __attribute__ ((aligned(64)));
524 struct iovec vnet_iov[2][2] = { 524 struct iovec vnet_iov[2][2] = {
525 { { .iov_base = vnet_hdr[0], .iov_len = sizeof(vnet_hdr[0]) }, 525 { { .iov_base = vnet_hdr[0], .iov_len = sizeof(vnet_hdr[0]) },
526 { .iov_base = vnet_buf[0], .iov_len = sizeof(vnet_buf[0]) } }, 526 { .iov_base = vnet_buf[0], .iov_len = sizeof(vnet_buf[0]) } },
diff --git a/drivers/misc/mic/card/mic_virtio.c b/drivers/misc/mic/card/mic_virtio.c
index 4dce912f9ea6..20c567b1760b 100644
--- a/drivers/misc/mic/card/mic_virtio.c
+++ b/drivers/misc/mic/card/mic_virtio.c
@@ -520,8 +520,8 @@ static void mic_scan_devices(struct mic_driver *mdrv, bool remove)
520 struct device *dev; 520 struct device *dev;
521 int ret; 521 int ret;
522 522
523 for (i = mic_aligned_size(struct mic_bootparam); 523 for (i = sizeof(struct mic_bootparam); i < MIC_DP_SIZE;
524 i < MIC_DP_SIZE; i += mic_total_desc_size(d)) { 524 i += mic_total_desc_size(d)) {
525 d = mdrv->dp + i; 525 d = mdrv->dp + i;
526 dc = (void __iomem *)d + mic_aligned_desc_size(d); 526 dc = (void __iomem *)d + mic_aligned_desc_size(d);
527 /* 527 /*
diff --git a/drivers/misc/mic/card/mic_virtio.h b/drivers/misc/mic/card/mic_virtio.h
index 2c5c22c93ba8..d0407ba53bb7 100644
--- a/drivers/misc/mic/card/mic_virtio.h
+++ b/drivers/misc/mic/card/mic_virtio.h
@@ -42,8 +42,8 @@
42 42
43static inline unsigned mic_desc_size(struct mic_device_desc __iomem *desc) 43static inline unsigned mic_desc_size(struct mic_device_desc __iomem *desc)
44{ 44{
45 return mic_aligned_size(*desc) 45 return sizeof(*desc)
46 + ioread8(&desc->num_vq) * mic_aligned_size(struct mic_vqconfig) 46 + ioread8(&desc->num_vq) * sizeof(struct mic_vqconfig)
47 + ioread8(&desc->feature_len) * 2 47 + ioread8(&desc->feature_len) * 2
48 + ioread8(&desc->config_len); 48 + ioread8(&desc->config_len);
49} 49}
@@ -67,8 +67,7 @@ mic_vq_configspace(struct mic_device_desc __iomem *desc)
67} 67}
68static inline unsigned mic_total_desc_size(struct mic_device_desc __iomem *desc) 68static inline unsigned mic_total_desc_size(struct mic_device_desc __iomem *desc)
69{ 69{
70 return mic_aligned_desc_size(desc) + 70 return mic_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
71 mic_aligned_size(struct mic_device_ctrl);
72} 71}
73 72
74int mic_devices_init(struct mic_driver *mdrv); 73int mic_devices_init(struct mic_driver *mdrv);
diff --git a/drivers/misc/mic/host/mic_virtio.c b/drivers/misc/mic/host/mic_virtio.c
index 945a3d0fe227..efe8da4401e9 100644
--- a/drivers/misc/mic/host/mic_virtio.c
+++ b/drivers/misc/mic/host/mic_virtio.c
@@ -467,7 +467,7 @@ static int mic_copy_dp_entry(struct mic_vdev *mvdev,
467 } 467 }
468 468
469 /* Find the first free device page entry */ 469 /* Find the first free device page entry */
470 for (i = mic_aligned_size(struct mic_bootparam); 470 for (i = sizeof(struct mic_bootparam);
471 i < MIC_DP_SIZE - mic_total_desc_size(dd_config); 471 i < MIC_DP_SIZE - mic_total_desc_size(dd_config);
472 i += mic_total_desc_size(devp)) { 472 i += mic_total_desc_size(devp)) {
473 devp = mdev->dp + i; 473 devp = mdev->dp + i;
diff --git a/include/uapi/linux/mic_common.h b/include/uapi/linux/mic_common.h
index 17e7d95e4f53..d0ec46d88d2a 100644
--- a/include/uapi/linux/mic_common.h
+++ b/include/uapi/linux/mic_common.h
@@ -23,12 +23,7 @@
23 23
24#include <linux/virtio_ring.h> 24#include <linux/virtio_ring.h>
25 25
26#ifndef __KERNEL__ 26#define __mic_align(a, x) (((a) + (x) - 1) & ~((x) - 1))
27#define ALIGN(a, x) (((a) + (x) - 1) & ~((x) - 1))
28#define __aligned(x) __attribute__ ((aligned(x)))
29#endif
30
31#define mic_aligned_size(x) ALIGN(sizeof(x), 8)
32 27
33/** 28/**
34 * struct mic_device_desc: Virtio device information shared between the 29 * struct mic_device_desc: Virtio device information shared between the
@@ -49,7 +44,7 @@ struct mic_device_desc {
49 __u8 config_len; 44 __u8 config_len;
50 __u8 status; 45 __u8 status;
51 __u64 config[0]; 46 __u64 config[0];
52} __aligned(8); 47} __attribute__ ((aligned(8)));
53 48
54/** 49/**
55 * struct mic_device_ctrl: Per virtio device information in the device page 50 * struct mic_device_ctrl: Per virtio device information in the device page
@@ -74,7 +69,7 @@ struct mic_device_ctrl {
74 __u8 used_address_updated; 69 __u8 used_address_updated;
75 __s8 c2h_vdev_db; 70 __s8 c2h_vdev_db;
76 __s8 h2c_vdev_db; 71 __s8 h2c_vdev_db;
77} __aligned(8); 72} __attribute__ ((aligned(8)));
78 73
79/** 74/**
80 * struct mic_bootparam: Virtio device independent information in device page 75 * struct mic_bootparam: Virtio device independent information in device page
@@ -93,7 +88,7 @@ struct mic_bootparam {
93 __s8 h2c_config_db; 88 __s8 h2c_config_db;
94 __u8 shutdown_status; 89 __u8 shutdown_status;
95 __u8 shutdown_card; 90 __u8 shutdown_card;
96} __aligned(8); 91} __attribute__ ((aligned(8)));
97 92
98/** 93/**
99 * struct mic_device_page: High level representation of the device page 94 * struct mic_device_page: High level representation of the device page
@@ -119,7 +114,7 @@ struct mic_vqconfig {
119 __u64 address; 114 __u64 address;
120 __u64 used_address; 115 __u64 used_address;
121 __u16 num; 116 __u16 num;
122} __aligned(8); 117} __attribute__ ((aligned(8)));
123 118
124/* 119/*
125 * The alignment to use between consumer and producer parts of vring. 120 * The alignment to use between consumer and producer parts of vring.
@@ -173,15 +168,13 @@ struct mic_vring {
173 int len; 168 int len;
174}; 169};
175 170
176#define mic_aligned_desc_size(d) ALIGN(mic_desc_size(d), 8) 171#define mic_aligned_desc_size(d) __mic_align(mic_desc_size(d), 8)
177 172
178#ifndef INTEL_MIC_CARD 173#ifndef INTEL_MIC_CARD
179static inline unsigned mic_desc_size(const struct mic_device_desc *desc) 174static inline unsigned mic_desc_size(const struct mic_device_desc *desc)
180{ 175{
181 return mic_aligned_size(*desc) 176 return sizeof(*desc) + desc->num_vq * sizeof(struct mic_vqconfig)
182 + desc->num_vq * mic_aligned_size(struct mic_vqconfig) 177 + desc->feature_len * 2 + desc->config_len;
183 + desc->feature_len * 2
184 + desc->config_len;
185} 178}
186 179
187static inline struct mic_vqconfig * 180static inline struct mic_vqconfig *
@@ -201,8 +194,7 @@ static inline __u8 *mic_vq_configspace(const struct mic_device_desc *desc)
201} 194}
202static inline unsigned mic_total_desc_size(struct mic_device_desc *desc) 195static inline unsigned mic_total_desc_size(struct mic_device_desc *desc)
203{ 196{
204 return mic_aligned_desc_size(desc) + 197 return mic_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl);
205 mic_aligned_size(struct mic_device_ctrl);
206} 198}
207#endif 199#endif
208 200