qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] net: cadence_gem: check packet size in gem_recieve
@ 2016-01-15  7:00 P J P
  2016-01-18  2:57 ` Jason Wang
  0 siblings, 1 reply; 4+ messages in thread
From: P J P @ 2016-01-15  7:00 UTC (permalink / raw)
  To: QEMU Developers
  Cc: Jason Wang, qemu-arm, Prasad J Pandit, Ling Liu,
	Michael S. Tsirkin

From: Prasad J Pandit <pjp@fedoraproject.org>

While receiving packets in 'gem_receive' routine, if Frame Check
Sequence(FCS) is enabled, it copies the packet into a local
buffer without checking its size. Add check to validate packet
length against the buffer size to avoid buffer overflow.

Reported-by: Ling Liu <liuling-it@360.cn>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 hw/net/cadence_gem.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
index 3639fc1..c3a273b 100644
--- a/hw/net/cadence_gem.c
+++ b/hw/net/cadence_gem.c
@@ -677,10 +677,14 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
     } else {
         unsigned crc_val;
 
+        if (size > sizeof(rxbuf) - sizeof(crc_val)) {
+            size = sizeof(rxbuf) - sizeof(crc_val);
+        }
+        bytes_to_copy = size;
+
         /* The application wants the FCS field, which QEMU does not provide.
          * We must try and calculate one.
          */
-
         memcpy(rxbuf, buf, size);
         memset(rxbuf + size, 0, sizeof(rxbuf) - size);
         rxbuf_ptr = rxbuf;
-- 
2.5.0

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

end of thread, other threads:[~2016-01-18  6:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-15  7:00 [Qemu-devel] [PATCH] net: cadence_gem: check packet size in gem_recieve P J P
2016-01-18  2:57 ` Jason Wang
2016-01-18  5:34   ` P J P
2016-01-18  6:49     ` Jason Wang

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).