From patchwork Tue Oct 9 22:39:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Sun X-Patchwork-Id: 981553 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="floCoDTW"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42VBxF2GxBz9s89 for ; Wed, 10 Oct 2018 09:39:29 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id E3A41B5A; Tue, 9 Oct 2018 22:39:26 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 099777A9 for ; Tue, 9 Oct 2018 22:39:26 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B96194DA for ; Tue, 9 Oct 2018 22:39:25 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id k19-v6so1589329pfi.1 for ; Tue, 09 Oct 2018 15:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=GxvKwhH4Z3aIFgGwlOMsrc4skNAdQGKHHbbOsWbEvNw=; b=floCoDTWcWYPpJgAwZliiPueED14sN+hYcmdXG/fzoyHtaF1XEArOgl/4zkEF02mkw n9N6+d8JbdQ4x1ZF/K7IzP8SmF+w7wPyqROgFfyodfxTXuiJnwgx99pdykPxhg5Ohn9T VcsDaGeAWllPcyzmIFj7AQfano0FomBtXHeAFMSZcE06aQJQsb4lAVwhsHQMRInNwOai GmsT8oFLkRNotEqLdthMUFli07P6awtBsMb8WUPYCe5DeW8nWxEffyYFEZLbg0Bv4Ndd LNqOMQV5zQVpSkzwY3Ppuvo9yIC9kBCJxg7DlBmFPKxPdhfseE/zM3bAfV0vaAYHVy5d 499g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GxvKwhH4Z3aIFgGwlOMsrc4skNAdQGKHHbbOsWbEvNw=; b=EfPwRcpPls1xSFj3LnILUl2tjAIxdXe3yzcKNryO0FU/UhiXhsjw+09XwC65NGyc+p MPCFW6CFkanovN2BhVRuGvEfvrp2dRA/2Mh2CnDJoDrlm9UEv8YUJg0rOjmAXxgKIvcm 10nf25GC6E7a9RZwynGRmBPKgUIzuGIh3rVlMVEcfiJ+G2oW+f0AyayF69DafkzU8vWo 9njrCQPp0DeJPzQrhP3ZYOGVNhPI0ew7gwBhHdVzlt/fzWHC7jVAeIpqsANV7wat6xAA s4jo194Db8xsqGbS9Sf4jNKZm7q085Mf/HcSDAuxxtah+oz57XrCLBOd1yfx0hfMhN20 LbMw== X-Gm-Message-State: ABuFfohL7Mz1db9zsmCa/bwltOYCR06/l40rNI3BvlZmNDwqD9KcYO9S R8T9uBOXmwzeIioyZL249DCqR9ic X-Google-Smtp-Source: ACcGV63tvGr3OTBbIvgrDSDvlaW8gN+hrapLyV5DNfdoBXCZop+D4elzI5FFCFiPZFbWxKNmOq+ENA== X-Received: by 2002:a63:c912:: with SMTP id o18-v6mr27125661pgg.331.1539124765071; Tue, 09 Oct 2018 15:39:25 -0700 (PDT) Received: from kern417.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id n13-v6sm24127537pgr.73.2018.10.09.15.39.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 15:39:24 -0700 (PDT) From: Yifeng Sun To: dev@openvswitch.org Date: Tue, 9 Oct 2018 15:39:17 -0700 Message-Id: <1539124758-7478-1-git-send-email-pkusunyifeng@gmail.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 1/2] odp-util: Fix a bug that causes stack overflow X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org ofpbuf_put_hex doesn't know buf's length and only checks buf's content to process. This is dangerous. This patch fixes it. Reported-at: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10865 Reported-at: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10863 Reported-at: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10855 Signed-off-by: Yifeng Sun --- lib/odp-util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/odp-util.c b/lib/odp-util.c index 7705bb30ae21..d482d5bcf968 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -2107,6 +2107,7 @@ parse_odp_push_nsh_action(const char *s, struct ofpbuf *actions) if (ovs_scan_len(s, &n, "md2=0x%511[0-9a-fA-F]", buf)) { ofpbuf_use_stub(&b, metadata, NSH_CTX_HDRS_MAX_LEN); + buf[n - 6] = '\0'; ofpbuf_put_hex(&b, buf, &mdlen); /* Pad metadata to 4 bytes. */ padding = PAD_SIZE(mdlen, 4); From patchwork Tue Oct 9 22:39:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Sun X-Patchwork-Id: 981554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OLhYM+Xl"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42VBxd2yDsz9s89 for ; Wed, 10 Oct 2018 09:39:49 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A7D5CC21; Tue, 9 Oct 2018 22:39:28 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id CA6737A9 for ; Tue, 9 Oct 2018 22:39:26 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 834504DA for ; Tue, 9 Oct 2018 22:39:26 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id j23-v6so1582248pfi.4 for ; Tue, 09 Oct 2018 15:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=c53zCPlSZXrkQsP4wSkDdH+aQR27oWmrhyAbmD7UMN4=; b=OLhYM+Xl5y4JVqMLe7L4C42r+YMDs74n2Usyh+7zZNJi8yNwyAfGu96BWoRd4269gW 2AzwC2wtVI6K+9Waxg9edIpumM51IRTjunSc+q36NEVquJMK17cshrPbk+5qTR2yHipe VYqP6ljmXl5Bwn/zNIgrJ4NsHIMEKlIiKJlglwKYHsdOK7RA1b7S8ruAHgeYzhdd6NA9 IOzM/VayCM+4+8+GV++EqkVyyLACits3Qb6WEYOVMw6uWjSJVN5wuFEBf96e0jbtflTC Y7fviGC2i5T9s2osJcZf3K+8+RBxnyZgLyFRiic3vo+ut+aCl1kdgkhOT1M5D5p0K1Tp ECTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=c53zCPlSZXrkQsP4wSkDdH+aQR27oWmrhyAbmD7UMN4=; b=J0w7JARUS5kquX6ULRV8tqdhCn3XEoTdL8b7WV6QJ9yDID2MzTOv/cVzV81qQUyKa/ hTeNL42j4eNBCzTWyoSCa3fJ+wEgAOh6LO6lnZ1BeeWbkksaVV43ISjpLoBiq5bezX82 uAUC+w2xLM7yQMfNPvmhx9iPvnm5WW2u6ErWD7QSqpxi0pInHJqb1qMIm5ifiQ6fe1Cg u+CmWGzxi2iHmB7vQT+DrsN5fKnIwBmrpczxjJhS2IAi2GDLN7g8lQl7k9nN3YN6BrCK W8abOJ+QXDE9uD+XmqCVTA351cExhJC3mV5t55QDNaAYyiU7YeS2zYU+IQXwbCfRJUH1 Hdtg== X-Gm-Message-State: ABuFfohlXyAIL7J5zC+q5BtpDUCqTpXHyaTxLaMXON2/fjA38RfqfTnf ICf+UMgFBYEzsCGZ3lFG/do8Mpyy X-Google-Smtp-Source: ACcGV62+V2ysbTeKvJiHQlfdVJNj0TG0wOlhTXot22rkXyGh2jj/BIzkJiOBsAY2j7DA6onLjvCv+Q== X-Received: by 2002:a63:ea07:: with SMTP id c7-v6mr10759060pgi.361.1539124765891; Tue, 09 Oct 2018 15:39:25 -0700 (PDT) Received: from kern417.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id n13-v6sm24127537pgr.73.2018.10.09.15.39.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 15:39:25 -0700 (PDT) From: Yifeng Sun To: dev@openvswitch.org Date: Tue, 9 Oct 2018 15:39:18 -0700 Message-Id: <1539124758-7478-2-git-send-email-pkusunyifeng@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1539124758-7478-1-git-send-email-pkusunyifeng@gmail.com> References: <1539124758-7478-1-git-send-email-pkusunyifeng@gmail.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 2/2] odp-util: Handle returning when parse_odp_key_mask_attr handles ufid X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When parse_odp_key_mask_attr runs into ufid, it returns length of ufid without appending data into ofpbufs. This commit adds additional checking for this case. Found this bug when debugging https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10850, but not certain it is related. Signed-off-by: Yifeng Sun --- lib/odp-util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/odp-util.c b/lib/odp-util.c index d482d5bcf968..f53530db40aa 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -2216,9 +2216,10 @@ parse_odp_action(const char *s, const struct simap *port_names, struct nlattr mask[1024 / sizeof(struct nlattr)]; struct ofpbuf maskbuf = OFPBUF_STUB_INITIALIZER(mask); struct nlattr *nested, *key; - size_t size; + size_t size, old_size; start_ofs = nl_msg_start_nested(actions, OVS_ACTION_ATTR_SET); + old_size = actions->size; retval = parse_odp_key_mask_attr(s + 4, port_names, actions, &maskbuf); if (retval < 0) { ofpbuf_uninit(&maskbuf); @@ -2233,7 +2234,7 @@ parse_odp_action(const char *s, const struct simap *port_names, key = nested + 1; size = nl_attr_get_size(mask); - if (size == nl_attr_get_size(key)) { + if (old_size != actions->size && size == nl_attr_get_size(key)) { /* Change to masked set action if not fully masked. */ if (!is_all_ones(mask + 1, size)) { /* Remove padding of eariler key payload */