[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4f460d31-c4da-8a58-8ee5-7735f5260f08@suse.com>
Date: Fri, 9 Jul 2021 15:58:37 +0200
From: Juergen Gross <jgross@...e.com>
To: Roger Pau Monné <roger.pau@...rix.com>
Cc: xen-devel@...ts.xenproject.org, linux-block@...r.kernel.org,
linux-kernel@...r.kernel.org,
Boris Ostrovsky <boris.ostrovsky@...cle.com>,
Stefano Stabellini <sstabellini@...nel.org>,
Konrad Rzeszutek Wilk <konrad.wilk@...cle.com>,
Jens Axboe <axboe@...nel.dk>
Subject: Re: [PATCH v2 3/3] xen/blkfront: don't trust the backend response
data blindly
On 09.07.21 11:42, Roger Pau Monné wrote:
> On Thu, Jul 08, 2021 at 02:43:45PM +0200, Juergen Gross wrote:
>> Today blkfront will trust the backend to send only sane response data.
>> In order to avoid privilege escalations or crashes in case of malicious
>> backends verify the data to be within expected limits. Especially make
>> sure that the response always references an outstanding request.
>>
>> Introduce a new state of the ring BLKIF_STATE_ERROR which will be
>> switched to in case an inconsistency is being detected. Recovering from
>> this state is possible only via removing and adding the virtual device
>> again (e.g. via a suspend/resume cycle).
>>
>> Signed-off-by: Juergen Gross <jgross@...e.com>
>
> Acked-by: Roger Pau Monné <roger.pau@...rix.com>
>> @@ -1555,11 +1561,17 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
>>
>> spin_lock_irqsave(&rinfo->ring_lock, flags);
>> again:
>> - rp = rinfo->ring.sring->rsp_prod;
>> - rmb(); /* Ensure we see queued responses up to 'rp'. */
>> + rp = READ_ONCE(rinfo->ring.sring->rsp_prod);
>> + virt_rmb(); /* Ensure we see queued responses up to 'rp'. */
>
> Is the READ_ONCE strictly needed? Doesn't the barrier prevent rp from
> not being loaded at this point?
I asked Jan the same and he didn't want to rule that out. Additionally
the READ_ONCE() helps against (rather improbable) load tearing of the
compiler.
>> + op = rinfo->shadow[id].req.operation;
>> + if (op == BLKIF_OP_INDIRECT)
>> + op = rinfo->shadow[id].req.u.indirect.indirect_op;
>> + if (bret.operation != op) {
>> + pr_alert("%s: response has wrong operation (%u instead of %u)\n",
>> + info->gd->disk_name, bret.operation, op);
>
> You could also use op_name here, but I guess this could mask the
> operation as 'unknown' for any number out of the defined ones.
This case shouldn't happen normally, so having the numerical value is
enough and will help for hiding any undefined op.
>> @@ -1635,8 +1662,8 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
>> case BLKIF_OP_READ:
>> case BLKIF_OP_WRITE:
>> if (unlikely(bret.status != BLKIF_RSP_OKAY))
>> - dev_dbg(&info->xbdev->dev, "Bad return from blkdev data "
>> - "request: %x\n", bret.status);
>> + dev_dbg_ratelimited(&info->xbdev->dev,
>> + "Bad return from blkdev data request: %x\n", bret.status);
>
> Since you are touching the line, could you use %#x here? It's IMO not
> obvious from the context this status will be printed in hex base. Also
> bret.status parameter could be split into a newline.
Fine with me.
Juergen
Download attachment "OpenPGP_0xB0DE9DD628BF132F.asc" of type "application/pgp-keys" (3092 bytes)
Download attachment "OpenPGP_signature" of type "application/pgp-signature" (496 bytes)
Powered by blists - more mailing lists