From patchwork Wed Oct 12 04:29:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9372037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 71B8C60839 for ; Wed, 12 Oct 2016 04:30:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 571782923D for ; Wed, 12 Oct 2016 04:30:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BA402926A; Wed, 12 Oct 2016 04:30:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 011652923D for ; Wed, 12 Oct 2016 04:30:05 +0000 (UTC) Received: from localhost ([::1]:59094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buBB6-0001vm-6I for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Oct 2016 00:30:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buBAp-0001vd-AF for qemu-devel@nongnu.org; Wed, 12 Oct 2016 00:29:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1buBAm-0003IE-41 for qemu-devel@nongnu.org; Wed, 12 Oct 2016 00:29:47 -0400 Received: from mail-it0-x243.google.com ([2607:f8b0:4001:c0b::243]:34140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1buBAl-0003Ho-VW for qemu-devel@nongnu.org; Wed, 12 Oct 2016 00:29:44 -0400 Received: by mail-it0-x243.google.com with SMTP id e203so3245003itc.1 for ; Tue, 11 Oct 2016 21:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:subject:date; bh=4b3pB/pyc66BD37hdBU4sIRSy76OgJJA1Z7LN4pwMH0=; b=XdXleaoKW7iLrfOdZyWHU0/+azHGWt1xlVsPH+xqH7mp35+6d+oAkpI+PAFIAZz06d kzKx4yXGwWdTMVxktnNzHhDVLUSFhveV8EH/6J8jGxMugyNcJBaDFgzhlQ5w+NrM/PXn 5c+W6C2Nx4TcIZWKpZg1NHA7uaADQE45Wqx1swz9lfzZJM1fKCHSPqlhUHt1MfAqf/Zl Ns3etGYljJvZdOAvEOfK3U3yNdwMhTfJQ85lpWByPNhv7ryQ+utvCy2CkyOol6dpwefz XZ2AtsIcoYU+fAHd1If5xCB+a1q1VtFerRoTtP5HYPCPpL8AvXo6/pAgZMgm8GgtqKtE FLaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=4b3pB/pyc66BD37hdBU4sIRSy76OgJJA1Z7LN4pwMH0=; b=HWIBkiU/LNXF4ZPQJo9/M4LtNLNqe/wFjCMdktGqzhmig9zvF3sJEXppI+zxzf+8kW JdlltiOztpDHZK10PFwWZGSwIzSHW2ToQULbNz9VNHRUH6HNIf9+mlu0M5RehGUuTTU6 h0ZKSgJFs1aU4pZKE9KLHkdEEekv+6j0a+CPqgWwXbX2uNFa+FPTDHtfzMX986IM0h1E 5I+9/XpEkjWFuCg1kbueaNxleO6neyDJm7X818UJsz5hynBdTUlqdvBIGqcTcR5CW/4M Yl/TVBGlmFEWiHpKIwMVh1Q5+IsLCc8lGTaJ0cZfz39jX4YTxa+/TdDmo69d7uS67sjQ gWMw== X-Gm-Message-State: AA6/9RlrtiH8Yt0z8CA8aIly2m82r77qY/Y/qBZvMYgfrGfGJyL/3SXZ2ezor36GG8EXHQ== X-Received: by 10.107.168.148 with SMTP id e20mr1446234ioj.44.1476246583051; Tue, 11 Oct 2016 21:29:43 -0700 (PDT) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id v69sm2948781itc.1.2016.10.11.21.29.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Oct 2016 21:29:42 -0700 (PDT) Message-ID: <57fdbc36.486b240a.941a3.ac8a@mx.google.com> X-Google-Original-Message-ID: <1476246559-4476-1-git-send-email-Qiang(liqiang6-s@360.cn)> From: Li Qiang X-Google-Original-From: Li Qiang(liqiang6-s@360.cn) To: groug@kaod.org, qemu-devel@nongnu.org Date: Tue, 11 Oct 2016 21:29:19 -0700 X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c0b::243 Subject: [Qemu-devel] [PATCH] 9pfs: fix integer overflow issue in xattr read/write X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Li Qiang In 9pfs xattr read/write function, it mix to use unsigned/signed ,32/64 bits integers. This will causes oob read/write issues. This patch fix this. Signed-off-by: Li Qiang --- hw/9pfs/9p.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index e4040dc..8b50bfb 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1642,21 +1642,21 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, { ssize_t err; size_t offset = 7; - int read_count; - int64_t xattr_len; + uint64_t read_count; + uint64_t xattr_len; V9fsVirtioState *v = container_of(s, V9fsVirtioState, state); VirtQueueElement *elem = v->elems[pdu->idx]; xattr_len = fidp->fs.xattr.len; + if (xattr_len < off) { + read_count = 0; + goto over_read_count; + } read_count = xattr_len - off; if (read_count > max_count) { read_count = max_count; - } else if (read_count < 0) { - /* - * read beyond XATTR value - */ - read_count = 0; } +over_read_count: err = pdu_marshal(pdu, offset, "d", read_count); if (err < 0) { return err; @@ -1982,22 +1982,19 @@ static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp, { int i, to_copy; ssize_t err = 0; - int write_count; - int64_t xattr_len; + uint64_t write_count; + uint64_t xattr_len; size_t offset = 7; xattr_len = fidp->fs.xattr.len; + if (xattr_len < off) { + err = -ENOSPC; + goto out; + } write_count = xattr_len - off; if (write_count > count) { write_count = count; - } else if (write_count < 0) { - /* - * write beyond XATTR value len specified in - * xattrcreate - */ - err = -ENOSPC; - goto out; } err = pdu_marshal(pdu, offset, "d", write_count); if (err < 0) {