All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Drivers: hv: vmbus: vmbus_requestor data structure
@ 2020-06-25 15:37 Andres Beltran
  2020-06-25 15:37 ` [PATCH 1/3] Drivers: hv: vmbus: Add vmbus_requestor data structure for VMBus hardening Andres Beltran
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Andres Beltran @ 2020-06-25 15:37 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu
  Cc: linux-hyperv, linux-kernel, mikelley, parri.andrea,
	Andres Beltran, linux-scsi, netdev, James E.J. Bottomley,
	Martin K. Petersen, David S. Miller, Jakub Kicinski

From: Andres Beltran (Microsoft) <lkmlabelt@gmail.com>

Currently, VMbus drivers use pointers into guest memory as request IDs
for interactions with Hyper-V. To be more robust in the face of errors
or malicious behavior from a compromised Hyper-V, avoid exposing
guest memory addresses to Hyper-V. Also avoid Hyper-V giving back a
bad request ID that is then treated as the address of a guest data
structure with no validation. Instead, encapsulate these memory
addresses and provide small integers as request IDs.

The first patch creates the definitions for the data structure, provides
helper methods to generate new IDs and retrieve data, and
allocates/frees the memory needed for vmbus_requestor.

The second and third patches make use of vmbus_requestor to send request
IDs to Hyper-V in storvsc and netvsc respectively.

Thanks.
Andres Beltran

Cc: linux-scsi@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>

Andres Beltran (3):
  Drivers: hv: vmbus: Add vmbus_requestor data structure for VMBus
    hardening
  scsi: storvsc: Use vmbus_requestor to generate transaction ids for
    VMBus hardening
  hv_netvsc: Use vmbus_requestor to generate transaction ids for VMBus
    hardening

 drivers/hv/channel.c              | 150 ++++++++++++++++++++++++++++++
 drivers/net/hyperv/hyperv_net.h   |  10 ++
 drivers/net/hyperv/netvsc.c       |  56 +++++++++--
 drivers/net/hyperv/rndis_filter.c |   1 +
 drivers/scsi/storvsc_drv.c        |  62 ++++++++++--
 include/linux/hyperv.h            |  22 +++++
 6 files changed, 283 insertions(+), 18 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [PATCH 1/3] Drivers: hv: vmbus: Add vmbus_requestor data structure for VMBus hardening
@ 2020-06-29 18:19 Andres Beltran
  2020-06-29 19:06 ` Wei Liu
  0 siblings, 1 reply; 16+ messages in thread
From: Andres Beltran @ 2020-06-29 18:19 UTC (permalink / raw)
  To: Wei Liu, Andres Beltran
  Cc: KY Srinivasan, Haiyang Zhang, Stephen Hemminger, linux-hyperv,
	linux-kernel, Michael Kelley, parri.andrea

From: linux-hyperv-owner@vger.kernel.org <linux-hyperv-owner@vger.kernel.org> On Behalf
Of Wei Liu. Sent: Friday, June 26, 2020 9:20 AM
> >  static int __vmbus_open(struct vmbus_channel *newchannel,
> >  		       void *userdata, u32 userdatalen,
> >  		       void (*onchannelcallback)(void *context), void *context)
> > @@ -122,6 +186,7 @@ static int __vmbus_open(struct vmbus_channel *newchannel,
> >  	u32 send_pages, recv_pages;
> >  	unsigned long flags;
> >  	int err;
> > +	int rqstor;
> >
> >  	if (userdatalen > MAX_USER_DEFINED_BYTES)
> >  		return -EINVAL;
> > @@ -132,6 +197,14 @@ static int __vmbus_open(struct vmbus_channel *newchannel,
> >  	if (newchannel->state != CHANNEL_OPEN_STATE)
> >  		return -EINVAL;
> >
> > +	/* Create and init requestor */
> > +	if (newchannel->rqstor_size) {
> > +		rqstor = vmbus_alloc_requestor(&newchannel->requestor,
> > +					       newchannel->rqstor_size);
> 
> You can simply use err here to store the return value or even get rid of
> rqstor by doing

Right. I will do that.

> > @@ -937,3 +1014,75 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void
> *buffer,
> >  				  buffer_actual_len, requestid, true);
> >  }
> >  EXPORT_SYMBOL_GPL(vmbus_recvpacket_raw);
> > +
> > +/*
> > + * vmbus_next_request_id - Returns a new request id. It is also
> > + * the index at which the guest memory address is stored.
> > + * Uses a spin lock to avoid race conditions.
> > + * @rqstor: Pointer to the requestor struct
> > + * @rqst_add: Guest memory address to be stored in the array
> > + */
> > +u64 vmbus_next_request_id(struct vmbus_requestor *rqstor, u64 rqst_addr)
> > +{
> > +	unsigned long flags;
> > +	u64 current_id;
> > +
> > +	spin_lock_irqsave(&rqstor->req_lock, flags);
> 
> Do you really need the irqsave variant here? I.e. is there really a
> chance this code is reachable from an interrupt handler?

Other VMBus drivers will also need to use this functionality, and
some of them will be called with interrupts disabled. So, I think
we should keep the irqsave variant here.

Andres.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-06-29 21:45 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-25 15:37 [PATCH 0/3] Drivers: hv: vmbus: vmbus_requestor data structure Andres Beltran
2020-06-25 15:37 ` [PATCH 1/3] Drivers: hv: vmbus: Add vmbus_requestor data structure for VMBus hardening Andres Beltran
2020-06-26 13:19   ` Wei Liu
2020-06-25 15:37 ` [PATCH 2/3] scsi: storvsc: Use vmbus_requestor to generate transaction IDs " Andres Beltran
2020-06-25 22:20   ` kernel test robot
2020-06-26 13:35   ` Wei Liu
2020-06-25 15:37 ` [PATCH 3/3] hv_netvsc: " Andres Beltran
2020-06-25 18:57   ` Haiyang Zhang
2020-06-25 23:37   ` kernel test robot
2020-06-25 23:37     ` kernel test robot
2020-06-25 18:22 ` [PATCH 0/3] Drivers: hv: vmbus: vmbus_requestor data structure Andrea Parri
2020-06-26 13:42 ` Wei Liu
2020-06-26 14:48   ` Andrea Parri
2020-06-26 20:57     ` Wei Liu
2020-06-29 18:19 [PATCH 1/3] Drivers: hv: vmbus: Add vmbus_requestor data structure for VMBus hardening Andres Beltran
2020-06-29 19:06 ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.