Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2487671imm; Mon, 24 Sep 2018 05:20:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV61/8Oz5rjtHptH9wy0TYXOe5exuGChwIlDlBtWlW4yFOiFuCrpM8vc0iqF6VJ641k295UXu X-Received: by 2002:a63:ee15:: with SMTP id e21-v6mr9287423pgi.421.1537791627026; Mon, 24 Sep 2018 05:20:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537791627; cv=none; d=google.com; s=arc-20160816; b=f1tgraFvsg41YYN1k9Isknj1oCowYCwihITDYJidGBOVRlvlTpq3STRFrkVeE8b6y9 J5OCDgamCqS20fj7+v/r6wbdoH8y1oxkoViqe1yBV08OtzdWUrCIwcO23EVFW3wkNtze Lswsp3I706E0tpPoQRWGyprLXHjlkdDk4yR4ZT0vifUdVUcCIepcAQGABXf17Gm51all C9HJrNomV7EcBhOmCf1PrTqB7WYVVE1wONU4EA8WPEqjU9e9SBlFKw5wiqYSQ9nZon+k HTkml0cM9WlpPp8dOCBO6YdPSqwqxYKX7ExmD2mgSgOmnVHocXRktDwrqsH8TDnfj7th Rflg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=U3iYvMYhkrLyv+nw3mgwwEFjp9Ez5pEtj3TaRcRq/Y8=; b=e18zI0tcRVsoYQmyUpNWzfRC4Bh1rXFj1ht4xi3NHiwDlT1T9FQZ4TrKUG2HHOhz7Q bzQh2GT7bAy20Bwp272nmqw0GWApKIsY8/RsIGo+4h598AjeGOnZnzI7nmBg1vp2UUC4 2xw+iBJtudE/02FkieKrOP4c4lOlulYABxkhwugSeuBY/rDAgYM2ovzH/tKXx5sIKQiO NE13zBjTxODfgly+OlBFUhny2HkMqGCuiCszBYxS6hDj/iuk8MIqcMH0jFsXgjiW/JxX TVQJTxjba1++E/nZ/TA+gVYt9ELarhpTWoAGPCoteubyU2mBbsq9Lqlxv40HcLD35kfv 1ZWw== 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 bd1-v6si36090386plb.156.2018.09.24.05.20.11; Mon, 24 Sep 2018 05:20:26 -0700 (PDT) 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 S1732660AbeIXSUd (ORCPT + 99 others); Mon, 24 Sep 2018 14:20:33 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56158 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730495AbeIXSUc (ORCPT ); Mon, 24 Sep 2018 14:20:32 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B2DDE107E; Mon, 24 Sep 2018 12:18:40 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Boris Brezillon , Sasha Levin Subject: [PATCH 4.14 111/173] mtdchar: fix overflows in adjustment of `count` Date: Mon, 24 Sep 2018 13:52:25 +0200 Message-Id: <20180924113124.210874398@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113114.334025954@linuxfoundation.org> References: <20180924113114.334025954@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn [ Upstream commit 6c6bc9ea84d0008024606bf5ba10519e20d851bf ] The first checks in mtdchar_read() and mtdchar_write() attempt to limit `count` such that `*ppos + count <= mtd->size`. However, they ignore the possibility of `*ppos > mtd->size`, allowing the calculation of `count` to wrap around. `mtdchar_lseek()` prevents seeking beyond mtd->size, but the pread/pwrite syscalls bypass this. I haven't found any codepath on which this actually causes dangerous behavior, but it seems like a sensible change anyway. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Jann Horn Signed-off-by: Boris Brezillon Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/mtdchar.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -160,8 +160,12 @@ static ssize_t mtdchar_read(struct file pr_debug("MTD_read\n"); - if (*ppos + count > mtd->size) - count = mtd->size - *ppos; + if (*ppos + count > mtd->size) { + if (*ppos < mtd->size) + count = mtd->size - *ppos; + else + count = 0; + } if (!count) return 0; @@ -246,7 +250,7 @@ static ssize_t mtdchar_write(struct file pr_debug("MTD_write\n"); - if (*ppos == mtd->size) + if (*ppos >= mtd->size) return -ENOSPC; if (*ppos + count > mtd->size)