[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 13/16] xen-blkback: Implement diskseq checks


  • To: Demi Marie Obenour <demi@xxxxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Wed, 7 Jun 2023 10:20:08 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yznqWHdJgNxhKmCmJ6V5rM3xWpehs3izcIMgPp7Rcec=; b=GCCEL/y1lhNGMT2djey6VWmZP8Uboa/lp4VZBLb2+eNpSCDgbtc/oLFs/Y+mKErd72YykxaGlU6fMm50GBBtoq04ARaP1ZgfMBvkatqfHLnq+ncDnB3d06cYhxPT7i/JKvIl1GAfeVGNDHBo12xS9PUXxnq6Cm6f+ikAcvStLnoS+1CUbukScvMW9PPNTWnvyTuwFP030HtAMgiG9RB5D7pBplSzSU8E9fvFBZeHQ97BZaeYvmHMvPKqGN2XNBlt7P9fkitz4LVwj0gnadBToLPaLReZ7bfOvPGTzRQ+3vXc9yfSA1KMLHr3mHcBqfebyXtgOuIE+Am7QGLaleW/9A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TeFQp/wQ2cZmyjfWMKDOXP0csNQ3uF2ZDxXdgdgOpQqjc8RiLNK+lACAvD0cO1aDVPzXoJn2+PDTpQEMa2dp5BWQIzNQPR1HnTZMNoTP4XKw4hWiA5yzsLOrN4gNnt3xy68oXVLHD3rYPMlfCXOt3Uc9stDjf8PCY8DXK0Npa843I8WN4xIeQj/knHAiBjAsLQnlByW38wfe5gnYLSjd2vWreImbGG4l14IV9pvTpBpZ8T34UEnpvGbAITx4psH1MvWxBtJY9Tvvz4bh/iRbEGxTP4MV2ijIYe426/dE7PBgb/yTAaUpe5o0nxWPFkHO8lgHZ3p3oe61Y7up+/kQHQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Jens Axboe <axboe@xxxxxxxxx>, Alasdair Kergon <agk@xxxxxxxxxx>, Mike Snitzer <snitzer@xxxxxxxxxx>, dm-devel@xxxxxxxxxx, Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, linux-block@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 07 Jun 2023 08:20:44 +0000
  • Ironport-data: A9a23:hv9wvqrZruozFl7eaZjqBXfnoBJeBmJaZRIvgKrLsJaIsI4StFCzt garIBmPbPiJYGf3fYx/Pti/p0xS7JWDy4BkGgFvqythHyoR+JuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpA1c/Ek/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKq04GtwUmAWP6gR5weAzyZNVfrzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXAAwDa0yqu+G7+u6ES85opu48KszpZYxK7xmMzRmBZRonabbqZvyToPV+jHI3jM0IGuvCb c0EbzYpdA7HfxBEJlYQDtQ5gfusgX78NTZfrTp5p4JuuzSVkFM3jeiraYSEEjCJbZw9ckKwv GXJ8n6/GhgHHNee1SCE4jSngeqncSbTAdtOT+3lrKQ26LGV7i8MARMbVmWFm/+Wk36TW+thK U4K0RN7+MDe82TuFLERRSaQrHOBvzYdXcRRCOww7AyRyqvS7B2dD2JCRTlEAPQvpMUxSBQp2 0WPktevCT8HmLSaSlqH+7uUpC/0Mi8QRUcZYy4YXwYfy9ruuoc+ilTIVNkLOKKwy9H4Bzz06 yqHoCg3m/MYistj/6Cy51XOmT+vjpnPUA8u5w/TU36l7wV2f4qsbcqj7l2zxfJBKpuJC1OFu 3MHs9aR4fpIDpyXkiGJBuIXE9mB4/eDLS2ZglN1GZQl3yqi9mTlfo1K5jx6YkBzPa4saTLvJ UPepw5VzJtSJ2exK796ZZqrDMYnxrSmEs7qPs04dfJLa5l1MQWBrCdnYBfJ23i3yRZ916YiJ Z2cbMCgS24ADrhqxya3QOFb1qI3wic5xiXYQpWTIwmb7IdyrUW9Ed8tWGZipMhihE9YiG05K +piCvY=
  • Ironport-hdrordr: A9a23:WsiKNq7f0Egz0g+ZOQPXwPfXdLJyesId70hD6qm+c20tTiX4rb HXoB1/73XJYVkqKRQdcLy7Scu9qDbnhP1ICOoqXItKPjOW3FdARbsKheDfKn/bexEWndQtsp uIHZIObuEYzmIXsS852mSF+hobr+VvOZrHudvj
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Jun 06, 2023 at 01:01:20PM -0400, Demi Marie Obenour wrote:
> On Tue, Jun 06, 2023 at 10:25:47AM +0200, Roger Pau Monné wrote:
> > On Tue, May 30, 2023 at 04:31:13PM -0400, Demi Marie Obenour wrote:
> > > This allows specifying a disk sequence number in XenStore.  If it does
> > > not match the disk sequence number of the underlying device, the device
> > > will not be exported and a warning will be logged.  Userspace can use
> > > this to eliminate race conditions due to major/minor number reuse.
> > > Old kernels do not support the new syntax, but a later patch will allow
> > > userspace to discover that the new syntax is supported.
> > > 
> > > Signed-off-by: Demi Marie Obenour <demi@xxxxxxxxxxxxxxxxxxxxxx>
> > > ---
> > >  drivers/block/xen-blkback/xenbus.c | 112 +++++++++++++++++++++++------
> > >  1 file changed, 89 insertions(+), 23 deletions(-)
> > > 
> > > diff --git a/drivers/block/xen-blkback/xenbus.c 
> > > b/drivers/block/xen-blkback/xenbus.c
> > > index 
> > > 4807af1d58059394d7a992335dabaf2bc3901721..9c3eb148fbd802c74e626c3d7bcd69dcb09bd921
> > >  100644
> > > --- a/drivers/block/xen-blkback/xenbus.c
> > > +++ b/drivers/block/xen-blkback/xenbus.c
> > > @@ -24,6 +24,7 @@ struct backend_info {
> > >   struct xenbus_watch     backend_watch;
> > >   unsigned                major;
> > >   unsigned                minor;
> > > + unsigned long long      diskseq;
> > 
> > Since diskseq is declared as u64 in gendisk, better use the same type
> > here too?
> 
> simple_strtoull() returns an unsigned long long, and C permits unsigned
> long long to be larger than 64 bits.

Right, but the type of gendisk is u64.  It's fine if you want to store
the result of simple_strtoull() into an unsigned long long and do
whatever checks to assert it matches the format expected by gendisk,
but ultimately the field type would better use u64 for consistency IMO.

> > > @@ -725,10 +749,46 @@ static void backend_changed(struct xenbus_watch 
> > > *watch,
> > >           return;
> > >   }
> > >  
> > > - if (be->major | be->minor) {
> > > -         if (be->major != major || be->minor != minor)
> > > -                 pr_warn("changing physical device (from %x:%x to %x:%x) 
> > > not supported.\n",
> > > -                         be->major, be->minor, major, minor);
> > > + diskseq_str = xenbus_read(XBT_NIL, dev->nodename, "diskseq", 
> > > &diskseq_len);
> > > + if (IS_ERR(diskseq_str)) {
> > > +         int err = PTR_ERR(diskseq_str);
> > > +         diskseq_str = NULL;
> > > +
> > > +         /*
> > > +          * If this does not exist, it means legacy userspace that does 
> > > not
> > > +          * support diskseq.
> > > +          */
> > > +         if (unlikely(!XENBUS_EXIST_ERR(err))) {
> > > +                 xenbus_dev_fatal(dev, err, "reading diskseq");
> > > +                 return;
> > > +         }
> > > +         diskseq = 0;
> > > + } else if (diskseq_len <= 0) {
> > > +         xenbus_dev_fatal(dev, -EFAULT, "diskseq must not be empty");
> > > +         goto fail;
> > > + } else if (diskseq_len > 16) {
> > > +         xenbus_dev_fatal(dev, -ERANGE, "diskseq too long: got %d but 
> > > limit is 16",
> > > +                          diskseq_len);
> > > +         goto fail;
> > > + } else if (diskseq_str[0] == '0') {
> > > +         xenbus_dev_fatal(dev, -ERANGE, "diskseq must not start with 
> > > '0'");
> > > +         goto fail;
> > > + } else {
> > > +         char *diskseq_end;
> > > +         diskseq = simple_strtoull(diskseq_str, &diskseq_end, 16);
> > > +         if (diskseq_end != diskseq_str + diskseq_len) {
> > > +                 xenbus_dev_fatal(dev, -EINVAL, "invalid diskseq");
> > > +                 goto fail;
> > > +         }
> > > +         kfree(diskseq_str);
> > > +         diskseq_str = NULL;
> > > + }
> > 
> > Won't it be simpler to use xenbus_scanf() with %llx formatter?
> 
> xenbus_scanf() doesn’t check for overflow and accepts lots of junk it
> really should not.  Should this be fixed in xenbus_scanf()?

That would be my preference, so that you can use it here instead of
kind of open-coding it.

> > Also, we might want to fetch "physical-device" and "diskseq" inside
> > the same xenstore transaction.
> 
> Should the rest of the xenstore reads be included in the same
> transaction?

I guess it would make the code simpler to indeed fetch everything
inside the same transaction.

> > Also, you tie this logic to the "physical-device" watch, which
> > strictly implies that the "diskseq" node must be written to xenstore
> > before the "physical-device" node.  This seems fragile, but I don't
> > see much better optiono since the "diskseq" is optional.
> 
> What about including the diskseq in the "physical-device" node?  Perhaps
> use diskseq@major:minor syntax?

Hm, how would you know whether the blkback instance in the kernel
supports the diskseq syntax in physical-device?

Can you fetch a disk using a diskseq identifier?

Why I understand that this is an extra safety check in order to assert
blkback is opening the intended device, is this attempting to fix some
existing issue?

I'm not sure I see how the major:minor numbers would point to a
different device than the one specified by the toolstack unless the
admin explicitly messes with the devices before blkback has got time
to open them.  But then the admin can already do pretty much
everything it wants with the system.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.