Skip to content

Commit 11e8e55

Browse files
jbeulichgregkh
authored andcommitted
xen-blkback: don't leak stack data via response ring
commit 089bc0143f489bd3a4578bdff5f4ca68fb26f341 upstream. Rather than constructing a local structure instance on the stack, fill the fields directly on the shared ring, just like other backends do. Build on the fact that all response structure flavors are actually identical (the old code did make this assumption too). This is XSA-216. Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> [bwh: Backported to 4.4: adjust context] Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 49630dd commit 11e8e55

2 files changed

Lines changed: 17 additions & 31 deletions

File tree

drivers/block/xen-blkback/blkback.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,33 +1407,34 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
14071407
static void make_response(struct xen_blkif *blkif, u64 id,
14081408
unsigned short op, int st)
14091409
{
1410-
struct blkif_response resp;
1410+
struct blkif_response *resp;
14111411
unsigned long flags;
14121412
union blkif_back_rings *blk_rings = &blkif->blk_rings;
14131413
int notify;
14141414

1415-
resp.id = id;
1416-
resp.operation = op;
1417-
resp.status = st;
1418-
14191415
spin_lock_irqsave(&blkif->blk_ring_lock, flags);
14201416
/* Place on the response ring for the relevant domain. */
14211417
switch (blkif->blk_protocol) {
14221418
case BLKIF_PROTOCOL_NATIVE:
1423-
memcpy(RING_GET_RESPONSE(&blk_rings->native, blk_rings->native.rsp_prod_pvt),
1424-
&resp, sizeof(resp));
1419+
resp = RING_GET_RESPONSE(&blk_rings->native,
1420+
blk_rings->native.rsp_prod_pvt);
14251421
break;
14261422
case BLKIF_PROTOCOL_X86_32:
1427-
memcpy(RING_GET_RESPONSE(&blk_rings->x86_32, blk_rings->x86_32.rsp_prod_pvt),
1428-
&resp, sizeof(resp));
1423+
resp = RING_GET_RESPONSE(&blk_rings->x86_32,
1424+
blk_rings->x86_32.rsp_prod_pvt);
14291425
break;
14301426
case BLKIF_PROTOCOL_X86_64:
1431-
memcpy(RING_GET_RESPONSE(&blk_rings->x86_64, blk_rings->x86_64.rsp_prod_pvt),
1432-
&resp, sizeof(resp));
1427+
resp = RING_GET_RESPONSE(&blk_rings->x86_64,
1428+
blk_rings->x86_64.rsp_prod_pvt);
14331429
break;
14341430
default:
14351431
BUG();
14361432
}
1433+
1434+
resp->id = id;
1435+
resp->operation = op;
1436+
resp->status = st;
1437+
14371438
blk_rings->common.rsp_prod_pvt++;
14381439
RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&blk_rings->common, notify);
14391440
spin_unlock_irqrestore(&blkif->blk_ring_lock, flags);

drivers/block/xen-blkback/common.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ extern unsigned int xen_blkif_max_ring_order;
7474
struct blkif_common_request {
7575
char dummy;
7676
};
77-
struct blkif_common_response {
78-
char dummy;
79-
};
77+
78+
/* i386 protocol version */
8079

8180
struct blkif_x86_32_request_rw {
8281
uint8_t nr_segments; /* number of segments */
@@ -128,14 +127,6 @@ struct blkif_x86_32_request {
128127
} u;
129128
} __attribute__((__packed__));
130129

131-
/* i386 protocol version */
132-
#pragma pack(push, 4)
133-
struct blkif_x86_32_response {
134-
uint64_t id; /* copied from request */
135-
uint8_t operation; /* copied from request */
136-
int16_t status; /* BLKIF_RSP_??? */
137-
};
138-
#pragma pack(pop)
139130
/* x86_64 protocol version */
140131

141132
struct blkif_x86_64_request_rw {
@@ -192,18 +183,12 @@ struct blkif_x86_64_request {
192183
} u;
193184
} __attribute__((__packed__));
194185

195-
struct blkif_x86_64_response {
196-
uint64_t __attribute__((__aligned__(8))) id;
197-
uint8_t operation; /* copied from request */
198-
int16_t status; /* BLKIF_RSP_??? */
199-
};
200-
201186
DEFINE_RING_TYPES(blkif_common, struct blkif_common_request,
202-
struct blkif_common_response);
187+
struct blkif_response);
203188
DEFINE_RING_TYPES(blkif_x86_32, struct blkif_x86_32_request,
204-
struct blkif_x86_32_response);
189+
struct blkif_response __packed);
205190
DEFINE_RING_TYPES(blkif_x86_64, struct blkif_x86_64_request,
206-
struct blkif_x86_64_response);
191+
struct blkif_response);
207192

208193
union blkif_back_rings {
209194
struct blkif_back_ring native;

0 commit comments

Comments
 (0)