Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3304503imu; Sun, 11 Nov 2018 12:00:49 -0800 (PST) X-Google-Smtp-Source: AJdET5e5eUs8eei9PUNtHTpbpfYbV23eqhyWVQlEyGOKS8nG9NeigAayNOWgwRTRsMtkhR9E2EEm X-Received: by 2002:a63:ce50:: with SMTP id r16mr10645886pgi.217.1541966449249; Sun, 11 Nov 2018 12:00:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541966449; cv=none; d=google.com; s=arc-20160816; b=CHUpPr9Z5cTEeldZa07LJJBZDbpcoiHivoNecGExVsS9ho4nd1t/J3mcdnU+qIiUan Euq+076d1/Vo0EYIy+c6EMQUvMSeLvueSGKLj/RzbsryZl9Gr9AQ44LPvfMmUrTlTmLu j8O/1e0LyazF8cLuYOHgQF9F/xCPGMj/mcRkARl0BwOIToYx9c+J0ORx46ZLT571+wjv EiZviK3q9GH19+svE9MPjsq2IIMSztouDn9xROVu94ioraRLodnmee6GbUjPF05Ml9mf 9gYcZ4S6kkjYRj2dcpk3cIFb83cn+ujGMMpYSsiKbve1DdhYcaJpqBiRtN6kPi4Z3NuX Pdqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=ju9ytXOJQGvABLCtyGtLGIysM80+sakpCtlbgHPJuME=; b=cPXVa0c05dNcSjRNGGTU5lQ8APRYeSWt8Tapba4hAJdRC2QR2oBx7RZwqnK4nUsaHO gNcZSUy4363Du3HTSXxQlm+72wFh6KHxsHgDeCIzYU7BFHZ0Me+Bi2HjoAf2Ai1QgO77 58GYp1mw+0jWr8IOWDPbt7dTtZzbAx8Ar54ZYqP9qpWWmFMDLYDMDP+OrrOT8OAvHU0m B47WMj1QinhsmkhYNJ0uDWMZq8xF6HbDoP0hU+9w3PyI8PuPJswEd5pgOqMUvqMu92jG AGmUJtkNCdJ7WHyfmu8iupg5KkXbM3xFTVtWhXk1wSFcVopyFAgJBDO1MMy9hkg9XFYP FI1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5-v6si13293873pgw.352.2018.11.11.12.00.34; Sun, 11 Nov 2018 12:00:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729667AbeKLFtG (ORCPT + 99 others); Mon, 12 Nov 2018 00:49:06 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:51412 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730861AbeKLFsk (ORCPT ); Mon, 12 Nov 2018 00:48:40 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvt1-0000tu-L5; Sun, 11 Nov 2018 19:59:11 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsS-0001Xg-1O; Sun, 11 Nov 2018 19:58:36 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Silvio Cesare" , "Kees Cook" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 134/366] UBIFS: Fix potential integer overflow in allocation In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Silvio Cesare commit 353748a359f1821ee934afc579cf04572406b420 upstream. There is potential for the size and len fields in ubifs_data_node to be too large causing either a negative value for the length fields or an integer overflow leading to an incorrect memory allocation. Likewise, when the len field is small, an integer underflow may occur. Signed-off-by: Silvio Cesare Fixes: 1e51764a3c2ac ("UBIFS: add new flash file system") Signed-off-by: Kees Cook [bwh: Backported to 3.16: We have a different set of length variables in recomp_data_node()] Signed-off-by: Ben Hutchings --- fs/ubifs/journal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c @@ -1099,10 +1099,11 @@ out_free: static int recomp_data_node(struct ubifs_data_node *dn, int *new_len) { void *buf; - int err, len, compr_type, out_len; + int err, compr_type; + u32 len, out_len; out_len = le32_to_cpu(dn->size); - buf = kmalloc(out_len * WORST_COMPR_FACTOR, GFP_NOFS); + buf = kmalloc_array(out_len, WORST_COMPR_FACTOR, GFP_NOFS); if (!buf) return -ENOMEM;