Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp461456yba; Wed, 15 May 2019 04:31:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpssujBKT4xFQ8I2JmztB1bDXTi7smy2R2S15/GFID2VtInQDewLhumxkSNs1FvodCI9lg X-Received: by 2002:a17:902:e00a:: with SMTP id ca10mr44337660plb.18.1557919897963; Wed, 15 May 2019 04:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557919897; cv=none; d=google.com; s=arc-20160816; b=yw/8m4F/ZsLuZkpkj4eryQ+44gwN+mukf9pgFQ2BhHx/nglFD6li+RKIjwmlNzIseR kwTPRamKDJq6Wv6TW6/qK9W5Uok0nujs99duutSTJ3GFPXf5JUraackulZHa+EpbCULA AqUmx9eCeLxCjxjuSMMf0zDmZus3FMJhs6CZj6exFA4yD0pX/3qcj04Y4HWklERR3sac mYz1sIUJQb1PedgXO1R31hQeZdE4bQxuN2QfUnhZuai170vJzmeFE7r//q4Zl20/pJ4h /bOIIo2b8l3CvHHIKlju1gElIPkqA3Se2vNPC/oGlqizpVu67kacWiQV/IApGA8yj0kB XItw== 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:dkim-signature; bh=0X9js5b5opTr3lAu3mq+Jip31/aDtXbNoUqZogFBUVw=; b=vdNsxDEvXsj9p16Qlkc3uAgGwWRlg7dkV9+RwUx5sEYW4VCLjrG6cxHKPVSKn2rVBH o+B4NQjJTR3VyUrLJWPaD7AMiv7XRmQnREHhTtwkMvCDgd5M3VUGs/+I9V5E24uvo4HN 45jpVqPjPscCLdIYdLraNFemRv5CXpNiT5gyQ8rLiuR3jGyHjoZbjPiXOq2XqChyBh8J 7WHglyBxwYtLvBW7QUz6g9SVhGh6RAvM3t7Iwd4Kap2Pl7k/du1uBjG1k8h97mo5qjHj KVB77NZcOuVIDZoqcDeRpQTcJ/iabVaVxQUteRjHomGt4vCCUG4nEiiNHSey2lDDt/13 vE+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="mHtbIE/X"; 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 s31si1699716pga.207.2019.05.15.04.31.22; Wed, 15 May 2019 04:31:37 -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; dkim=pass header.i=@kernel.org header.s=default header.b="mHtbIE/X"; 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 S1732527AbfEOL3S (ORCPT + 99 others); Wed, 15 May 2019 07:29:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:40466 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726542AbfEOL3P (ORCPT ); Wed, 15 May 2019 07:29:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4F2F6206BF; Wed, 15 May 2019 11:29:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919754; bh=3CBpc1fLJnHIj2l4Fa+AUaaNaeYCNUuCUI7rrM7kUBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mHtbIE/XMTIL8vHX3oH3bos/k21d3Nn758Rx1qQK0UAoap0Cx5y3NBLlSKLi2OlgZ QCCjUgOYxz/zHrXOJZLokZyOmZp4nbJ1oLlxROgrs4aHwQqmOKTRcZV9D4Ts5/lBuC ZJrRXoX1hlEh0T8ps6ansGHnSh3Qfpb1RogACo/g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liang ZhiCheng , Li RongQing , Ira Weiny , Jeff Moyer , Dan Williams , Sasha Levin Subject: [PATCH 5.0 027/137] libnvdimm/pmem: fix a possible OOB access when read and write pmem Date: Wed, 15 May 2019 12:55:08 +0200 Message-Id: <20190515090655.255284245@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit 9dc6488e84b0f64df17672271664752488cd6a25 ] If offset is not zero and length is bigger than PAGE_SIZE, this will cause to out of boundary access to a page memory Fixes: 98cc093cba1e ("block, THP: make block_device_operations.rw_page support THP") Co-developed-by: Liang ZhiCheng Signed-off-by: Liang ZhiCheng Signed-off-by: Li RongQing Reviewed-by: Ira Weiny Reviewed-by: Jeff Moyer Signed-off-by: Dan Williams Signed-off-by: Sasha Levin --- drivers/nvdimm/pmem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index bc2f700feef8a..0279eb1da3ef5 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -113,13 +113,13 @@ static void write_pmem(void *pmem_addr, struct page *page, while (len) { mem = kmap_atomic(page); - chunk = min_t(unsigned int, len, PAGE_SIZE); + chunk = min_t(unsigned int, len, PAGE_SIZE - off); memcpy_flushcache(pmem_addr, mem + off, chunk); kunmap_atomic(mem); len -= chunk; off = 0; page++; - pmem_addr += PAGE_SIZE; + pmem_addr += chunk; } } @@ -132,7 +132,7 @@ static blk_status_t read_pmem(struct page *page, unsigned int off, while (len) { mem = kmap_atomic(page); - chunk = min_t(unsigned int, len, PAGE_SIZE); + chunk = min_t(unsigned int, len, PAGE_SIZE - off); rem = memcpy_mcsafe(mem + off, pmem_addr, chunk); kunmap_atomic(mem); if (rem) @@ -140,7 +140,7 @@ static blk_status_t read_pmem(struct page *page, unsigned int off, len -= chunk; off = 0; page++; - pmem_addr += PAGE_SIZE; + pmem_addr += chunk; } return BLK_STS_OK; } -- 2.20.1