From patchwork Tue Apr 9 10:28:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Righi X-Patchwork-Id: 1082110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44dk6j3875z9sSC; Tue, 9 Apr 2019 20:29:15 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1hDo03-000796-8g; Tue, 09 Apr 2019 10:29:07 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1hDo01-00078q-Tp for kernel-team@lists.ubuntu.com; Tue, 09 Apr 2019 10:29:05 +0000 Received: from mail-wr1-f70.google.com ([209.85.221.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hDo01-0001b3-JI for kernel-team@lists.ubuntu.com; Tue, 09 Apr 2019 10:29:05 +0000 Received: by mail-wr1-f70.google.com with SMTP id m13so10562606wrr.17 for ; Tue, 09 Apr 2019 03:29:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tOk/PxruE77RVG+4gdCV5rIOAfRvyYN8MR0xIqm5mGI=; b=pn75h/rLSKC52EYsrt3Y6CqK2TixzxfVq6plcxKD52vEtabbqMY2H10b1pVyZtZVXT yCo0wZko/LtlXtjlJ0OkElr7ACB3e4SHyxZX0v5aGXbiV4oZq9G6fH3rzcDYmSnpO/+g crkO52B8HFstX3eLrmtmWZEC2uWbaTJ6ihKWupzAjMiOzi+Ye+2lZ1tEgOAxw4rhZk+J PNXJzu+zH5TY7NiSVeBLpGOg5rM46Awyup+ED6wSoSt/L2UHGDPugYQbZ89lZRM7z9dk R9wpClZH0Sj0VrXP9kPyAD1h+k71O8NiloBwB42n9RFYZwRWMff/GkG7wyKPyCNfr46C QeOA== X-Gm-Message-State: APjAAAUEw7VbzHNdcZacwRNF1MLAQC0vlQ8kTi2yz8pfTjIl78iQCkNQ lUc6hZX43VWVNJzSQVdVGCYsImMXPOvTGfP/NL7h7iq0m3xpAuMcPhROquXZlAOTZsaGNHRoEzb 4uGz4B/wVitsM9+60V8WGwyETo324Wxv464BOzxtqsg== X-Received: by 2002:a1c:730c:: with SMTP id d12mr21900637wmb.47.1554805745090; Tue, 09 Apr 2019 03:29:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZ4CruJCWRXXtDMVfPuVT1wsnuY46JA71o3ru7nxOkdqdO2yzsxbG0GD3kPeH6B55gDtlvmw== X-Received: by 2002:a1c:730c:: with SMTP id d12mr21900622wmb.47.1554805744832; Tue, 09 Apr 2019 03:29:04 -0700 (PDT) Received: from localhost.localdomain (host141-127-dynamic.17-87-r.retail.telecomitalia.it. [87.17.127.141]) by smtp.gmail.com with ESMTPSA id t74sm3329873wmt.3.2019.04.09.03.29.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Apr 2019 03:29:04 -0700 (PDT) From: Andrea Righi To: kernel-team@lists.ubuntu.com Subject: [SRU] [Trusty] [PATCH 1/1] openvswitch: fix flow actions reallocation Date: Tue, 9 Apr 2019 12:28:09 +0200 Message-Id: <20190409102809.21177-2-andrea.righi@canonical.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190409102809.21177-1-andrea.righi@canonical.com> References: <20190409102809.21177-1-andrea.righi@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" Buglink: https://bugs.launchpad.net/bugs/1813244 The flow action buffer can be resized if it's not big enough to contain all the requested flow actions. However, this resize doesn't take into account the new requested size, the buffer is only increased by a factor of 2x. This might be not enough to contain the new data, causing a buffer overflow, for example: [ 42.044472] ============================================================================= [ 42.045608] BUG kmalloc-96 (Not tainted): Redzone overwritten [ 42.046415] ----------------------------------------------------------------------------- [ 42.047715] Disabling lock debugging due to kernel taint [ 42.047716] INFO: 0x8bf2c4a5-0x720c0928. First byte 0x0 instead of 0xcc [ 42.048677] INFO: Slab 0xbc6d2040 objects=29 used=18 fp=0xdc07dec4 flags=0x2808101 [ 42.049743] INFO: Object 0xd53a3464 @offset=2528 fp=0xccdcdebb [ 42.050747] Redzone 76f1b237: cc cc cc cc cc cc cc cc ........ [ 42.051839] Object d53a3464: 6b 6b 6b 6b 6b 6b 6b 6b 0c 00 00 00 6c 00 00 00 kkkkkkkk....l... [ 42.053015] Object f49a30cc: 6c 00 0c 00 00 00 00 00 00 00 00 03 78 a3 15 f6 l...........x... [ 42.054203] Object acfe4220: 20 00 02 00 ff ff ff ff 00 00 00 00 00 00 00 00 ............... [ 42.055370] Object 21024e91: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ [ 42.056541] Object 070e04c3: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ [ 42.057797] Object 948a777a: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ [ 42.059061] Redzone 8bf2c4a5: 00 00 00 00 .... [ 42.060189] Padding a681b46e: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ Fix by making sure the new buffer is properly resized to contain all the requested data. BugLink: https://bugs.launchpad.net/bugs/1813244 Signed-off-by: Andrea Righi Acked-by: Pravin B Shelar Signed-off-by: David S. Miller (backported from commit f28cd2af22a0c134e4aa1c64a70f70d815d473fb) Signed-off-by: Andrea Righi Acked-by: Juerg Haefliger --- net/openvswitch/flow_netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c index 2bc1bc1aca3b..7ac03e1a799a 100644 --- a/net/openvswitch/flow_netlink.c +++ b/net/openvswitch/flow_netlink.c @@ -1149,14 +1149,14 @@ static struct nlattr *reserve_sfa_size(struct sw_flow_actions **sfa, struct sw_flow_actions *acts; int new_acts_size; - int req_size = NLA_ALIGN(attr_len); + size_t req_size = NLA_ALIGN(attr_len); int next_offset = offsetof(struct sw_flow_actions, actions) + (*sfa)->actions_len; if (req_size <= (ksize(*sfa) - next_offset)) goto out; - new_acts_size = ksize(*sfa) * 2; + new_acts_size = max(next_offset + req_size, ksize(*sfa) * 2); if (new_acts_size > MAX_ACTIONS_BUFSIZE) { if ((MAX_ACTIONS_BUFSIZE - next_offset) < req_size)