Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2990983imu; Sun, 9 Dec 2018 14:28:59 -0800 (PST) X-Google-Smtp-Source: AFSGD/UGoIGjF/4dmNer7+yAS64jMnIftT2vxb556PBH3DV0bSU5YgASUNobCaql/8KzwxY1v8gL X-Received: by 2002:a17:902:968d:: with SMTP id n13mr10075731plp.109.1544394539409; Sun, 09 Dec 2018 14:28:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544394539; cv=none; d=google.com; s=arc-20160816; b=i6FvN7n8DTJfkaVapUZ/dpavgPVhOkN/CfoSggAkuKW+UUSlQL6fyM6zCjBfqAFTBc laFQ5u5e22LmjzTcMziN8REQEUrgeWZXIFBEe0IcpATKsNa8+yh+X0DufCqjFM5VvQjh r0yldUIBj2uP6bY+cLlUEbdFxRAsy60u5k0kHtSbyNYBt23zeGnHipSYy+mVKZZM9V4r irGAi3/NLXbMYWTM85jZ5/K6zAlthbbcLs6CYg1mPVLvvCZSWZ/o9qQbRMDYpNfpHwe9 xIT6UJ5Sc7P0zhvWVNIQpwvppfx27rS/0szVAb1p1Stni8b7105U+/xDLB3X9gzGhxLQ SlHw== 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=mOmD4SBi7wHJlUkqZnTQw62NXuFv/y86llELAxLTzUE=; b=Z/7kt9AWKcP2imVcrTfX5m7lwxIAtk8GKjdQLPmm4GggRGUYAbrxPeG2IXKNGw1y/q FNGCSeYZGHtaQv4JebAYIMv46czQZmVwBK/FCIHqIlVB0yyun2uxMUXpqPrsYnEr6Lmg gmZNSbH5PkTX/14/WMn4gADV+r9FmgIx1upfasTFI2hoDSAAYpzSTI88XYKdAiSF5bzm 5rXW7mBx61BzwCIvn273EJJvJg4d7CLJtrlD6RUZjKbwFrgu8a9AS/el54yMXGlg+ooE mWq4e8wI1tafK3ScHq6M9FS72z0VAw7qSnCgHTsOkaTOJDb7TFDtJGw4XdcQENI9oQLN zdEw== 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 w2si8162813pgh.565.2018.12.09.14.28.44; Sun, 09 Dec 2018 14:28:59 -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 S1728633AbeLIW0X (ORCPT + 99 others); Sun, 9 Dec 2018 17:26:23 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34812 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726416AbeLIVzO (ORCPT ); Sun, 9 Dec 2018 16:55:14 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72d-0002po-WB; Sun, 09 Dec 2018 21:55:12 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72d-0003OW-JO; Sun, 09 Dec 2018 21:55:11 +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, "Kees Cook" , "Silvio Cesare" , "Richard Weinberger" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 140/328] ubifs: Check data node size before truncate In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 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.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Richard Weinberger commit 95a22d2084d72ea067d8323cc85677dba5d97cae upstream. Check whether the size is within bounds before using it. If the size is not correct, abort and dump the bad data node. Cc: Kees Cook Cc: Silvio Cesare Fixes: 1e51764a3c2ac ("UBIFS: add new flash file system") Reported-by: Silvio Cesare Signed-off-by: Richard Weinberger Reviewed-by: Kees Cook Signed-off-by: Richard Weinberger [bwh: Backported to 3.16: Drop first argument to ubifs_err()] Signed-off-by: Ben Hutchings --- fs/ubifs/journal.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c @@ -1186,7 +1186,16 @@ int ubifs_jnl_truncate(struct ubifs_info else if (err) goto out_free; else { - if (le32_to_cpu(dn->size) <= dlen) + int dn_len = le32_to_cpu(dn->size); + + if (dn_len <= 0 || dn_len > UBIFS_BLOCK_SIZE) { + ubifs_err("bad data node (block %u, inode %lu)", + blk, inode->i_ino); + ubifs_dump_node(c, dn); + goto out_free; + } + + if (dn_len <= dlen) dlen = 0; /* Nothing to do */ else { int compr_type = le16_to_cpu(dn->compr_type);