Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5994803ybc; Wed, 27 Nov 2019 13:05:27 -0800 (PST) X-Google-Smtp-Source: APXvYqzXq52aXW0lROn9b6e8Goe0p2VnpiKxvz8BsxuVqhgUA78XPc6Jtrubwa/FR+Ii/67jbY1b X-Received: by 2002:a50:91d0:: with SMTP id h16mr34186417eda.203.1574888727514; Wed, 27 Nov 2019 13:05:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888727; cv=none; d=google.com; s=arc-20160816; b=D4QPJ/qWqe0jronTkYVVYVzXTGpbrILi47D/EWUqNEoO4W8CWisJLpull8Dxg3hHV9 OcIlH2cn8XqZHpb0oLtXSNbzKS7FUHib/4EiYrfkwwjOF56NFbYjYNNm1G30Yn9xtCmN dcfR+3aKiswYVvR8jwwvw6HLmo9eB7C7qE0/XgzVR6896dWNEdpQGa4iObknoOkigTbT uNStDF3peUKLygRfQSbnciilLjO7t32LXTgFDqUF9TpcHeP/yurYwU54obqfyUixjEBQ drQkVbJjFoU8/PFZtSnB4qSCU3ExohTzUTygKaUwADin7wWS4igoPHqPF80B0FtO0fVD 4VKQ== 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=I8FMAVsOibGYmaaWtNeZrWfNw74KxY2AOoY0g82SjZo=; b=ndq/jxLEmX9++HRUUHtUJ+OtgNB8hYMXUK6KYzfESOIJvCJQaH1Tn26iJDsjz90aRh pS2YQw6zNr3oFm1zEJuK09BCCHy/uTJwGXslE8hFq3mkXuPZu9aoMj7uAx+lBd8I2sJT BF0Xvmi3sjdzy5Ci1wzivCsIBq7OwQHy4V7nz+HL+Gr4xLkc1USGlf2yueTIGELxuyw0 BWsY43b3+iDR33mO0hCfmW+jI/DLrLuk+1IUkE7lCcvFVq0YerIMjEw2lU5ElDXOQGBK 2ZM1mTfP/k6Z32phy7MSPe5Las4JmaUln2kAUxJdZyUsdLPQ/FzgzOtSwhZ2oG2CU1C7 yo5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rJNbUGRA; 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 dd21si4915769edb.111.2019.11.27.13.05.03; Wed, 27 Nov 2019 13:05:27 -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; dkim=pass header.i=@kernel.org header.s=default header.b=rJNbUGRA; 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 S1727351AbfK0VCK (ORCPT + 99 others); Wed, 27 Nov 2019 16:02:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:54682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730992AbfK0VCJ (ORCPT ); Wed, 27 Nov 2019 16:02:09 -0500 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 97EAA2158C; Wed, 27 Nov 2019 21:02:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888528; bh=qgKnA8ercINp8dTih9WIGTCvC7aWFs7CarrmJcobrQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rJNbUGRA+HnRNtLz/JfcsCnQp4g0SzS1RE8fQUZzRlcdK0hUMnxI11g+fg8D1ysPt qusVJv1iY1wDglGfZl+6aeI80wRwbCuGNdNldZ41rZ1yKqkRYrsbEqW+1BiF32LcdJ +KWjqRzHLSjHKa7TmdVY33ge6z+7QmyyFG6C32Zc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rasmus Villemoes , Andy Shevchenko , Yury Norov , Sudeep Holla , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 169/306] lib/bitmap.c: fix remaining space computation in bitmap_print_to_pagebuf Date: Wed, 27 Nov 2019 21:30:19 +0100 Message-Id: <20191127203127.754467394@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@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 From: Rasmus Villemoes [ Upstream commit ce1091d471107dbf6f91db66a480a25950c9b9ff ] For various alignments of buf, the current expression computes 4096 ok 4095 ok 8190 8189 ... 4097 i.e., if the caller has already written two bytes into the page buffer, len is 8190 rather than 4094, because PTR_ALIGN aligns up to the next boundary. So if the printed version of the bitmap is huge, scnprintf() ends up writing beyond the page boundary. I don't think any current callers actually write anything before bitmap_print_to_pagebuf, but the API seems to be designed to allow it. [akpm@linux-foundation.org: use offset_in_page(), per Andy] [akpm@linux-foundation.org: include mm.h for offset_in_page()] Link: http://lkml.kernel.org/r/20180818131623.8755-7-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes Reviewed-by: Andy Shevchenko Cc: Yury Norov Cc: Rasmus Villemoes Cc: Sudeep Holla Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- lib/bitmap.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 2fd07f6df0b85..c4ca9ceb09fe3 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -466,14 +467,15 @@ EXPORT_SYMBOL(bitmap_parse_user); * ranges if list is specified or hex digits grouped into comma-separated * sets of 8 digits/set. Returns the number of characters written to buf. * - * It is assumed that @buf is a pointer into a PAGE_SIZE area and that - * sufficient storage remains at @buf to accommodate the - * bitmap_print_to_pagebuf() output. + * It is assumed that @buf is a pointer into a PAGE_SIZE, page-aligned + * area and that sufficient storage remains at @buf to accommodate the + * bitmap_print_to_pagebuf() output. Returns the number of characters + * actually printed to @buf, excluding terminating '\0'. */ int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, int nmaskbits) { - ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf; + ptrdiff_t len = PAGE_SIZE - offset_in_page(buf); int n = 0; if (len > 1) -- 2.20.1