From nobody Tue Feb 10 01:34:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1596951184; cv=none; d=zohomail.com; s=zohoarc; b=aikjwdTElpjga6Z4okBaaqvqGRKa72cNfchivXAM7Zkq2xLxgILF2PVi4SfmVyHgfDKOujmY2b/TFdMIrVvN9winSY8Dp537Z0hEdaWTesHGS6X83ba6KPNdr+LWZY4y9vCZzldreR1KDzw64xCW/Jgfd1beIZrItmkhAlTPVxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596951184; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hVddOn2tPwkDkl3uxgdvuYzldMK4+FRk2QQMDeFIZWA=; b=bxHEw7jmdyJBSZ9yOmooQzjm2GkRHcQnf69/Jr7BXEmvpaO/l4VUQlS+YjQ/wQ7zq4B/ryG7iqmYLX+TMCDTQSF0X5hhu74+7f8y2dSyJBqjAiXMoTfW0z9rayP9bSaCvHbfSX8cXSHypwwSmDNC4SgHiH8UDSmPjKOgNsY2D0k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1596951184478749.5283501893094; Sat, 8 Aug 2020 22:33:04 -0700 (PDT) Received: from localhost ([::1]:55324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k4dx8-0003BT-KQ for importer@patchew.org; Sun, 09 Aug 2020 01:33:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k4dot-0006FW-Rh for qemu-devel@nongnu.org; Sun, 09 Aug 2020 01:24:31 -0400 Received: from mout.gmx.net ([212.227.17.21]:40491) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k4dor-0002pE-Ng for qemu-devel@nongnu.org; Sun, 09 Aug 2020 01:24:31 -0400 Received: from ls3530.fritz.box ([92.116.185.161]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MVeI8-1kCRog1tZM-00RXHM; Sun, 09 Aug 2020 07:24:06 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1596950646; bh=I/Sx/HdpIxh4i9UsobCMs9UPgI56qxrzVMpyXIjjkEc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=eVxhDhIknvGiPoRm5KPsYrNUo+0Q5NOiNs+j5v35zi/vSfuaeC/eQFGniICKXRJMY dsdwJ2FkiNojFbSAbBnkTW12OV0YowyGioxfrkwmkQUMJK/9W/T/cjuMhj6SNOt+o4 OCB0w0afDJz3jze7nZhmz2CQG6t9J/nOYbazR8qk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c From: Helge Deller To: peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PATCH v4 07/12] hw/display/artist: Refactor artist_rop8() to avoid buffer over-run Date: Sun, 9 Aug 2020 07:23:57 +0200 Message-Id: <20200809052402.31641-8-deller@gmx.de> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200809052402.31641-1-deller@gmx.de> References: <20200809052402.31641-1-deller@gmx.de> MIME-Version: 1.0 Content-Transfer-Encoding: qu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ldo83QlI6RirtX2pIr4wLWxUOhxpr+Ko2fff LE7zbDR4wG6X5HaHyfCkvB+LG/TtBXk3La2rqYsY2J/H2GYOqJsi7ZWO341DDCSnXLTTF4/JC LoSvxz0+WQeJbl2IlJQuQX81dpJmIsJE6xn7ekj1BE58H+eobT1htgbHTHHqBOtYiBTwuMFsn Pr05TKknA+EiWqY/rJ49uJQFl+cZvIRHeeBvVdXn87JHQykeOFulpmxOUpiMl1gPXXZU1/rdB Op4zyfqyFpSMCU85z+2T5KfTCNrMniTkwZXSCEOPE6o7JUpl+y8cqryAX+g3U9nMQC9CmB0+k knE1ov2e/+fFaBpJvFa/Xt2yiB6p4464urYluRheYcK5MQZu1RL+yhLxFfCGG8Frrk0G7bnMg NkA9HlyDPvV066xBdVWTh6R39hmecPYpThjN3e7xs3/FCHKGwjr1bsmAs+ZXXpixNyVZDeYzk a+xISCCjuh0AmetNe Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=212.227.17.21; envelope-from=deller@gmx.de; helo=mout.gmx.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/09 01:24:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Helge Deller , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 Invalid I/O writes can craft an offset out of the vram_buffer range. Instead of passing an unsafe pointer to artist_rop8(), pass the vram_buffer= and the offset. We can now check if the offset is in range before accessing it. We avoid: Program terminated with signal SIGSEGV, Segmentation fault. 284 *dst &=3D ~plane_mask; (gdb) bt #0 0x000056367b2085c0 in artist_rop8 (s=3D0x56367d38b510, dst=3D0x7f9f97= 2fffff , val=3D0 '\0= 00') at hw/display/artist.c:284 #1 0x000056367b209325 in draw_line (s=3D0x56367d38b510, x1=3D-20480, y1= =3D-1, x2=3D0, y2=3D17920, update_start=3Dtrue, skip_pix=3D-1, max_pix=3D-1= ) at hw/display/artist.c:646 Reported-by: LLVM libFuzzer Buglink: https://bugs.launchpad.net/qemu/+bug/1880326 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Helge Deller --- hw/display/artist.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/hw/display/artist.c b/hw/display/artist.c index a206afe641..47de17b9e9 100644 --- a/hw/display/artist.c +++ b/hw/display/artist.c @@ -273,11 +273,20 @@ static artist_rop_t artist_get_op(ARTISTState *s) return (s->image_bitmap_op >> 8) & 0xf; } -static void artist_rop8(ARTISTState *s, uint8_t *dst, uint8_t val) +static void artist_rop8(ARTISTState *s, struct vram_buffer *buf, + int offset, uint8_t val) { - const artist_rop_t op =3D artist_get_op(s); - uint8_t plane_mask =3D s->plane_mask & 0xff; + uint8_t plane_mask; + uint8_t *dst; + + if (offset < 0 || offset >=3D buf->size) { + qemu_log_mask(LOG_GUEST_ERROR, + "rop8 offset:%d bufsize:%u\n", offset, buf->size); + return; + } + dst =3D buf->data + offset; + plane_mask =3D s->plane_mask & 0xff; switch (op) { case ARTIST_ROP_CLEAR: @@ -375,7 +384,7 @@ static void vram_bit_write(ARTISTState *s, int posx, in= t posy, bool incr_x, for (i =3D 0; i < pix_count; i++) { uint32_t off =3D offset + pix_count - 1 - i; if (off < buf->size) { - artist_rop8(s, p + off, + artist_rop8(s, buf, off, (data & 1) ? (s->plane_mask >> 24) : 0); } data >>=3D 1; @@ -395,7 +404,7 @@ static void vram_bit_write(ARTISTState *s, int posx, in= t posy, bool incr_x, s->vram_bitmask & (1 << (28 + i))) { uint32_t off =3D offset + 3 - i; if (off < buf->size) { - artist_rop8(s, p + off, data8[ROP8OFF(i)]); + artist_rop8(s, buf, off, data8[ROP8OFF(i)]); } } } @@ -424,10 +433,10 @@ static void vram_bit_write(ARTISTState *s, int posx, = int posy, bool incr_x, if (!(s->image_bitmap_op & 0x20000000) || (vram_bitmask & mask)) { if (data & mask) { - artist_rop8(s, p + offset + i, s->fg_color); + artist_rop8(s, buf, offset + i, s->fg_color); } else { if (!(s->image_bitmap_op & 0x10000002)) { - artist_rop8(s, p + offset + i, s->bg_color); + artist_rop8(s, buf, offset + i, s->bg_color); } } } @@ -505,7 +514,7 @@ static void block_move(ARTISTState *s, int source_x, in= t source_y, int dest_x, if (dst + column > buf->size || src + column > buf->size) { continue; } - artist_rop8(s, buf->data + dst + column, buf->data[src + colum= n]); + artist_rop8(s, buf, dst + column, buf->data[src + column]); } } @@ -546,7 +555,7 @@ static void fill_window(ARTISTState *s, int startx, int= starty, offset =3D y * s->width; for (x =3D startx; x < startx + width; x++) { - artist_rop8(s, buf->data + offset + x, color); + artist_rop8(s, buf, offset + x, color); } } artist_invalidate_lines(buf, starty, height); @@ -559,7 +568,6 @@ static void draw_line(ARTISTState *s, int x1, int y1, i= nt x2, int y2, uint8_t color; int dx, dy, t, e, x, y, incy, diago, horiz; bool c1; - uint8_t *p; trace_artist_draw_line(x1, y1, x2, y2); @@ -628,16 +636,18 @@ static void draw_line(ARTISTState *s, int x1, int y1,= int x2, int y2, color =3D artist_get_color(s); do { + int ofs; + if (c1) { - p =3D buf->data + x * s->width + y; + ofs =3D x * s->width + y; } else { - p =3D buf->data + y * s->width + x; + ofs =3D y * s->width + x; } if (skip_pix > 0) { skip_pix--; } else { - artist_rop8(s, p, color); + artist_rop8(s, buf, ofs, color); } if (e > 0) { @@ -771,10 +781,10 @@ static void font_write16(ARTISTState *s, uint16_t val) for (i =3D 0; i < 16; i++) { mask =3D 1 << (15 - i); if (val & mask) { - artist_rop8(s, buf->data + offset + i, color); + artist_rop8(s, buf, offset + i, color); } else { if (!(s->image_bitmap_op & 0x20000000)) { - artist_rop8(s, buf->data + offset + i, s->bg_color); + artist_rop8(s, buf, offset + i, s->bg_color); } } } -- 2.21.3