linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Drivers: hv: vmbus: Fix variable assignments in hv_ringbuffer_read()
@ 2020-07-24 16:46 Andres Beltran
  2020-07-24 17:10 ` Stephen Hemminger
  0 siblings, 1 reply; 5+ messages in thread
From: Andres Beltran @ 2020-07-24 16:46 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu
  Cc: linux-hyperv, linux-kernel, mikelley, parri.andrea, skarade,
	Andres Beltran

Assignments to buffer_actual_len and requestid happen before packetlen
is checked to be within buflen. If this condition is true,
hv_ringbuffer_read() returns with these variables already set to some
value even though no data is actually read. This might create
inconsistencies in any routine calling hv_ringbuffer_read(). Assign values
to such pointers after the packetlen check.

Signed-off-by: Andres Beltran <lkmlabelt@gmail.com>
---
 drivers/hv/ring_buffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 356e22159e83..e277ce7372a4 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -350,12 +350,13 @@ int hv_ringbuffer_read(struct vmbus_channel *channel,
 
 	offset = raw ? 0 : (desc->offset8 << 3);
 	packetlen = (desc->len8 << 3) - offset;
-	*buffer_actual_len = packetlen;
-	*requestid = desc->trans_id;
 
 	if (unlikely(packetlen > buflen))
 		return -ENOBUFS;
 
+	*buffer_actual_len = packetlen;
+	*requestid = desc->trans_id;
+
 	/* since ring is double mapped, only one copy is necessary */
 	memcpy(buffer, (const char *)desc + offset, packetlen);
 
-- 
2.25.1


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

end of thread, other threads:[~2020-07-26 23:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 16:46 [PATCH] Drivers: hv: vmbus: Fix variable assignments in hv_ringbuffer_read() Andres Beltran
2020-07-24 17:10 ` Stephen Hemminger
2020-07-24 17:48   ` Haiyang Zhang
2020-07-24 23:04   ` Andres Beltran
2020-07-26 23:53     ` Haiyang Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).