From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57F49C43217 for ; Mon, 15 Nov 2021 23:21:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46C5B61AA7 for ; Mon, 15 Nov 2021 23:21:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353857AbhKOXY0 (ORCPT ); Mon, 15 Nov 2021 18:24:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:44598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244887AbhKOTSI (ORCPT ); Mon, 15 Nov 2021 14:18:08 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 156816342B; Mon, 15 Nov 2021 18:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637000694; bh=Ng46LKe/Z8bgw3kPd/kpqNG8NVKBNjbT94Qex4KdQcA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bZExK+DepFtF7xQbW2tormlsmJbeebl8P0Zfh+fms9wzHKJ6M6ptLrmxHT92mR0QC 9jh9z4uW4ApzoCzeAVImCPQxl5B0NOoYJqwpypM/oh7cctOAH7/8LP6/OwxYS2ruXJ sub6UAgaU7cLjXlRvLOXJTgsMt4krp7mepwj+HRM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Minchan Kim , Sergey Senozhatsky , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.14 757/849] zram: off by one in read_block_state() Date: Mon, 15 Nov 2021 18:04:00 +0100 Message-Id: <20211115165445.859699563@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211115165419.961798833@linuxfoundation.org> References: <20211115165419.961798833@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit a88e03cf3d190cf46bc4063a9b7efe87590de5f4 ] snprintf() returns the number of bytes it would have printed if there were space. But it does not count the NUL terminator. So that means that if "count == copied" then this has already overflowed by one character. This bug likely isn't super harmful in real life. Link: https://lkml.kernel.org/r/20210916130404.GA25094@kili Fixes: c0265342bff4 ("zram: introduce zram memory tracking") Signed-off-by: Dan Carpenter Cc: Minchan Kim Cc: Sergey Senozhatsky Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- drivers/block/zram/zram_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index fcaf2750f68f7..6383c81ac5b37 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -910,7 +910,7 @@ static ssize_t read_block_state(struct file *file, char __user *buf, zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.', zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.'); - if (count < copied) { + if (count <= copied) { zram_slot_unlock(zram, index); break; } -- 2.33.0