All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] correct size computation in m_cat
@ 2018-06-05 18:08 P J P
  2018-06-05 18:08 ` [Qemu-devel] [PATCH 1/2] slirp: correct size computation while concatenating mbuf P J P
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: P J P @ 2018-06-05 18:08 UTC (permalink / raw)
  To: Qemu Developers; +Cc: Samuel Thibault, Jan Kiszka, Prasad J Pandit

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

Hello,

While reassembling incoming fragmented datagrams, 'm_cat' routine
extends the 'mbuf' buffer if it has insufficient room. It computes
a wrong buffer size, which leads to overwriting adjacent heap buffer
area.

This patch set fixes this issue and formats m_cat() routine as per coding
style guide.

Thank you.
--
Prasad J Pandit (2):
  slirp: correct size computation while concatenating mbuf
  slirp: reformat m_cat routine

 slirp/mbuf.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

--
2.17.1

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

* [Qemu-devel] [PATCH 1/2] slirp: correct size computation while concatenating mbuf
  2018-06-05 18:08 [Qemu-devel] [PATCH 0/2] correct size computation in m_cat P J P
@ 2018-06-05 18:08 ` P J P
  2018-06-06  9:09   ` Samuel Thibault
  2018-06-05 18:08 ` [Qemu-devel] [PATCH 2/2] slirp: reformat m_cat routine P J P
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: P J P @ 2018-06-05 18:08 UTC (permalink / raw)
  To: Qemu Developers; +Cc: Samuel Thibault, Jan Kiszka, Prasad J Pandit

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

While reassembling incoming fragmented datagrams, 'm_cat' routine
extends the 'mbuf' buffer, if it has insufficient room. It computes
a wrong buffer size, which leads to overwriting adjacent heap buffer
area. Correct this size computation in m_cat.

Reported-by: ZDI Disclosures <zdi-disclosures@trendmicro.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 slirp/mbuf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/slirp/mbuf.c b/slirp/mbuf.c
index 5ff24559fd..0f45abd917 100644
--- a/slirp/mbuf.c
+++ b/slirp/mbuf.c
@@ -138,7 +138,7 @@ m_cat(struct mbuf *m, struct mbuf *n)
 	 * If there's no room, realloc
 	 */
 	if (M_FREEROOM(m) < n->m_len)
-		m_inc(m,m->m_size+MINCSIZE);
+		m_inc(m, m->m_len + n->m_len);
 
 	memcpy(m->m_data+m->m_len, n->m_data, n->m_len);
 	m->m_len += n->m_len;
@@ -158,12 +158,12 @@ m_inc(struct mbuf *m, int size)
 
         if (m->m_flags & M_EXT) {
 	  datasize = m->m_data - m->m_ext;
-          m->m_ext = g_realloc(m->m_ext, size);
+          m->m_ext = g_realloc(m->m_ext, size + datasize);
 	  m->m_data = m->m_ext + datasize;
         } else {
 	  char *dat;
 	  datasize = m->m_data - m->m_dat;
-          dat = g_malloc(size);
+      dat = g_malloc(size + datasize);
 	  memcpy(dat, m->m_dat, m->m_size);
 
 	  m->m_ext = dat;
@@ -171,7 +171,7 @@ m_inc(struct mbuf *m, int size)
 	  m->m_flags |= M_EXT;
         }
 
-        m->m_size = size;
+        m->m_size = size + datasize;
 
 }
 
-- 
2.17.1

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

* [Qemu-devel] [PATCH 2/2] slirp: reformat m_cat routine
  2018-06-05 18:08 [Qemu-devel] [PATCH 0/2] correct size computation in m_cat P J P
  2018-06-05 18:08 ` [Qemu-devel] [PATCH 1/2] slirp: correct size computation while concatenating mbuf P J P
@ 2018-06-05 18:08 ` P J P
  2018-06-06  9:18   ` Samuel Thibault
  2018-06-06  8:58 ` [Qemu-devel] [PATCH 0/2] correct size computation in m_cat no-reply
  2018-06-06 10:19 ` no-reply
  3 siblings, 1 reply; 8+ messages in thread
From: P J P @ 2018-06-05 18:08 UTC (permalink / raw)
  To: Qemu Developers; +Cc: Samuel Thibault, Jan Kiszka, Prasad J Pandit

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

Coding style changes to the m_cat routine and minor refactoring.

Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 slirp/mbuf.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/slirp/mbuf.c b/slirp/mbuf.c
index 0f45abd917..30e3b2719d 100644
--- a/slirp/mbuf.c
+++ b/slirp/mbuf.c
@@ -151,32 +151,28 @@ m_cat(struct mbuf *m, struct mbuf *n)
 void
 m_inc(struct mbuf *m, int size)
 {
-	int datasize;
+    int datasize;
 
-	/* some compiles throw up on gotos.  This one we can fake. */
-        if(m->m_size>size) return;
+    /* some compiles throw up on gotos. This one we can fake. */
+    if (m->m_size > size) {
+        return;
+    }
 
-        if (m->m_flags & M_EXT) {
-	  datasize = m->m_data - m->m_ext;
-          m->m_ext = g_realloc(m->m_ext, size + datasize);
-	  m->m_data = m->m_ext + datasize;
-        } else {
-	  char *dat;
-	  datasize = m->m_data - m->m_dat;
-      dat = g_malloc(size + datasize);
-	  memcpy(dat, m->m_dat, m->m_size);
-
-	  m->m_ext = dat;
-	  m->m_data = m->m_ext + datasize;
-	  m->m_flags |= M_EXT;
-        }
-
-        m->m_size = size + datasize;
+    if (m->m_flags & M_EXT) {
+        datasize = m->m_data - m->m_ext;
+        m->m_ext = g_realloc(m->m_ext, size + datasize);
+    } else {
+        datasize = m->m_data - m->m_dat;
+        m->m_ext = g_malloc(size + datasize);
+        memcpy(m->m_ext, m->m_dat, m->m_size);
+        m->m_flags |= M_EXT;
+    }
 
+    m->m_data = m->m_ext + datasize;
+    m->m_size = size + datasize;
 }
 
 
-
 void
 m_adj(struct mbuf *m, int len)
 {
-- 
2.17.1

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

* Re: [Qemu-devel] [PATCH 0/2] correct size computation in m_cat
  2018-06-05 18:08 [Qemu-devel] [PATCH 0/2] correct size computation in m_cat P J P
  2018-06-05 18:08 ` [Qemu-devel] [PATCH 1/2] slirp: correct size computation while concatenating mbuf P J P
  2018-06-05 18:08 ` [Qemu-devel] [PATCH 2/2] slirp: reformat m_cat routine P J P
@ 2018-06-06  8:58 ` no-reply
  2018-06-06 10:19 ` no-reply
  3 siblings, 0 replies; 8+ messages in thread
From: no-reply @ 2018-06-06  8:58 UTC (permalink / raw)
  To: ppandit; +Cc: famz, qemu-devel, samuel.thibault, pjp, jan.kiszka

Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20180605180836.21485-1-ppandit@redhat.com
Subject: [Qemu-devel] [PATCH 0/2] correct size computation in m_cat

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
769059abb8 slirp: reformat m_cat routine
9f938dc6a6 slirp: correct size computation while concatenating mbuf

=== OUTPUT BEGIN ===
Checking PATCH 1/2: slirp: correct size computation while concatenating mbuf...
ERROR: code indent should never use tabs
#24: FILE: slirp/mbuf.c:141:
+^I^Im_inc(m, m->m_len + n->m_len);$

total: 1 errors, 0 warnings, 30 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 2/2: slirp: reformat m_cat routine...
=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [Qemu-devel] [PATCH 1/2] slirp: correct size computation while concatenating mbuf
  2018-06-05 18:08 ` [Qemu-devel] [PATCH 1/2] slirp: correct size computation while concatenating mbuf P J P
@ 2018-06-06  9:09   ` Samuel Thibault
  2018-06-06 18:42     ` P J P
  0 siblings, 1 reply; 8+ messages in thread
From: Samuel Thibault @ 2018-06-06  9:09 UTC (permalink / raw)
  To: P J P; +Cc: Qemu Developers, Jan Kiszka, Prasad J Pandit

Hello,

P J P, le mar. 05 juin 2018 23:38:35 +0530, a ecrit:
> From: Prasad J Pandit <pjp@fedoraproject.org>
> 
> While reassembling incoming fragmented datagrams, 'm_cat' routine
> extends the 'mbuf' buffer, if it has insufficient room. It computes
> a wrong buffer size, which leads to overwriting adjacent heap buffer
> area. Correct this size computation in m_cat.
> 
> Reported-by: ZDI Disclosures <zdi-disclosures@trendmicro.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>

Applied to my tree with a couple documentation improvements, thanks!

Samuel

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

* Re: [Qemu-devel] [PATCH 2/2] slirp: reformat m_cat routine
  2018-06-05 18:08 ` [Qemu-devel] [PATCH 2/2] slirp: reformat m_cat routine P J P
@ 2018-06-06  9:18   ` Samuel Thibault
  0 siblings, 0 replies; 8+ messages in thread
From: Samuel Thibault @ 2018-06-06  9:18 UTC (permalink / raw)
  To: P J P; +Cc: Qemu Developers, Jan Kiszka, Prasad J Pandit

P J P, le mar. 05 juin 2018 23:38:36 +0530, a ecrit:
> From: Prasad J Pandit <pjp@fedoraproject.org>
> 
> Coding style changes to the m_cat routine and minor refactoring.

Fixed a bit and applied to my tree, thanks!

Samuel

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

* Re: [Qemu-devel] [PATCH 0/2] correct size computation in m_cat
  2018-06-05 18:08 [Qemu-devel] [PATCH 0/2] correct size computation in m_cat P J P
                   ` (2 preceding siblings ...)
  2018-06-06  8:58 ` [Qemu-devel] [PATCH 0/2] correct size computation in m_cat no-reply
@ 2018-06-06 10:19 ` no-reply
  3 siblings, 0 replies; 8+ messages in thread
From: no-reply @ 2018-06-06 10:19 UTC (permalink / raw)
  To: ppandit; +Cc: famz, qemu-devel, samuel.thibault, pjp, jan.kiszka

Hi,

This series failed build test on s390x host. Please find the details below.

Type: series
Message-id: 20180605180836.21485-1-ppandit@redhat.com
Subject: [Qemu-devel] [PATCH 0/2] correct size computation in m_cat

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with
# HEAD pointing to a commit that has the patches applied on top of "base"
# branch
set -e
echo "=== ENV ==="
env
echo "=== PACKAGES ==="
rpm -qa
echo "=== TEST BEGIN ==="
CC=$HOME/bin/cc
INSTALL=$PWD/install
BUILD=$PWD/build
echo -n "Using CC: "
realpath $CC
mkdir -p $BUILD $INSTALL
SRC=$PWD
cd $BUILD
$SRC/configure --cc=$CC --prefix=$INSTALL
make -j4
# XXX: we need reliable clean up
# make check -j4 V=1
make install
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
fatal: unable to access 'https://github.com/patchew-project/qemu/': Encountered end of file
error: Could not fetch 3c8cf5a9c21ff8782164d1def7f44bd888713384
Traceback (most recent call last):
  File "/home/fam/patchew/patchew-cli", line 409, in test_one
    git_clone_repo(clone, r["repo"], r["head"], logf)
  File "/home/fam/patchew/patchew-cli", line 48, in git_clone_repo
    stdout=logf, stderr=logf)
  File "/usr/lib64/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'remote', 'add', '-f', '--mirror=fetch', '3c8cf5a9c21ff8782164d1def7f44bd888713384', 'https://github.com/patchew-project/qemu']' returned non-zero exit status 1.



---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [Qemu-devel] [PATCH 1/2] slirp: correct size computation while concatenating mbuf
  2018-06-06  9:09   ` Samuel Thibault
@ 2018-06-06 18:42     ` P J P
  0 siblings, 0 replies; 8+ messages in thread
From: P J P @ 2018-06-06 18:42 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: Qemu Developers, Jan Kiszka

  Hello Samuel,

+-- On Wed, 6 Jun 2018, Samuel Thibault wrote --+
| > From: Prasad J Pandit <pjp@fedoraproject.org>
| > 
| > While reassembling incoming fragmented datagrams, 'm_cat' routine
| > extends the 'mbuf' buffer, if it has insufficient room. It computes
| > a wrong buffer size, which leads to overwriting adjacent heap buffer
| > area. Correct this size computation in m_cat.
| > 
| > Reported-by: ZDI Disclosures <zdi-disclosures@trendmicro.com>
| > Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
| 
| Applied to my tree with a couple documentation improvements, thanks!

  -> https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg01144.html

This is patch v1 with indentation fix flagged by checkpatch.pl. In case you 
prefer this one.

Thank you.
--
 - P J P
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

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

end of thread, other threads:[~2018-06-06 18:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-05 18:08 [Qemu-devel] [PATCH 0/2] correct size computation in m_cat P J P
2018-06-05 18:08 ` [Qemu-devel] [PATCH 1/2] slirp: correct size computation while concatenating mbuf P J P
2018-06-06  9:09   ` Samuel Thibault
2018-06-06 18:42     ` P J P
2018-06-05 18:08 ` [Qemu-devel] [PATCH 2/2] slirp: reformat m_cat routine P J P
2018-06-06  9:18   ` Samuel Thibault
2018-06-06  8:58 ` [Qemu-devel] [PATCH 0/2] correct size computation in m_cat no-reply
2018-06-06 10:19 ` no-reply

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.