Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2800080imm; Sun, 19 Aug 2018 05:39:10 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyE9xOiujExasNc65HJ+JLD5WWOm34EwBKT9+tvE/JGbhlpHJeSxTbu2Ws5Js6Sxvt/Rc/I X-Received: by 2002:a63:a053:: with SMTP id u19-v6mr12303840pgn.394.1534682350225; Sun, 19 Aug 2018 05:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534682350; cv=none; d=google.com; s=arc-20160816; b=QUmBT8G5UZoyKWd44x9tJuO2v5Mdiiua3K8bpTt7vyzVEw4m6yItj5qKpKcJ79AshS JSy+PgfCHo33EAh8zprYOsKXraIkMpAHwM1z8qRZS8B2LDYUnEgX6zbQMomID83r9Y3S ErwsnphmUgZcMt3u+IQLo39rRyrOcNyEDHU4R4ybO7zdjWNd0pazMr4YVVLcUJpKcz5D FyfNerQnLqZV5Fs9Z5qZZ4b++RLc1QoKdra0PyQpziQEYA2Kq1lyfNyg4XVuGVDVZX8g UhLoY1JKsjiwwKNBNqq6Bs7gmWUQVm8WxNSrrPvTUxUKqQKgETZF2DHUbgggdeDisT0O /Sbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=9jpuwE7438CL2SNEkAOfWIjFTB/AZa4CPofxdVeA1a8=; b=DFunjSYfsVFa/GzFrT9j9CSztgPjs+NXZ2Nh1SuL9+B6WbHXjNGy3m1AMMXTYExqhz WBt+YcFwetbE+eMO5nDnMjNqYvIj/PEfsfh5+5DwTMrUe7tyb5w8sztUF0SIdeIL7PtN s/XQ6zPuQKq5Lqk/DF1jHe1pjWVOqvrDa6igW35IGUTwXP+Qze7lW+TIXSu+1YMXhKHf AjJ7MNCGoqMrc7tziClL/up3Hr1URxqfUuMOiF4rbtfv5Bv9ykDvw7DIr54M2IDYgaQj O81lmeZ6JB+s1JwgNneP2TRRlfE26J5CuO4Tn0bCTFruidFxHCyom+VsOTL7Vq1B5eu/ uV6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gxg4ecLf; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10-v6si1821823pln.298.2018.08.19.05.38.55; Sun, 19 Aug 2018 05:39:10 -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=@gmail.com header.s=20161025 header.b=gxg4ecLf; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726507AbeHSPtN (ORCPT + 99 others); Sun, 19 Aug 2018 11:49:13 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:37590 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725956AbeHSPtN (ORCPT ); Sun, 19 Aug 2018 11:49:13 -0400 Received: by mail-qk0-f194.google.com with SMTP id f17-v6so1897251qkh.4 for ; Sun, 19 Aug 2018 05:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9jpuwE7438CL2SNEkAOfWIjFTB/AZa4CPofxdVeA1a8=; b=gxg4ecLfAosW4S/rPbbIU+5ol2GnnXRHcMnJLYnYczHjdFP8mszp65fCDnnFiD9AG5 B4AXL06pZPsVX6kDWU+3IEXGn2wMgL44hPHojRJ0Po+YpweKDes9w5qeeCD0RthQhGxz 4pU5K5xDl2S0KFc19BrbTSCjz0Xd7SWLyYVhaeV1HFQ6pKwiSoh8uC6gt7lh/+7kcnK1 KULMLRTuf1cOAMgbZBWDnLZ1/u/a5KQyaW2eJQfSdfEPuCu8wuq9lHtgjs5wOZ2dHqRi 3PcrBZv3QCJ4JoiYpOuG1fHoseVytq/1yuskQnd/i7/EbFryXJ6Ma69X7jLl+sFnkmp7 LSDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9jpuwE7438CL2SNEkAOfWIjFTB/AZa4CPofxdVeA1a8=; b=OSoF/ph4OxlpfkAn6PfhnTHNw7zw8QIDwrwdGzAfB3bjSmGHCXxJ+26NFW5ZgzCFZs pfwUPxl+gcjndoyFDymLASrJdJhD2g0XB51pmpPXpkeh4FunguOsOdiDZEOVF/Vispjc psfTTvOx8Vjd7hj/Pt1hHJ8bN7pM1dwmTsDx10UHU9pskTajhW6Fl54ERoJN8l9Qzl5G fnaArQ6dAonNVbESYHAUwNaihOAHMEPDTwxwvnTBpifDUNWlsfaktLySOw/XzqEfcWGf BTscmBgfG/kZRMI91+zkc+NHxI4eEUSy3b8xsjbwdL3DWWaXzS9WDbxzCd3APobFY7Wb sv2Q== X-Gm-Message-State: AOUpUlEgZp7CiAnaIlherhRnzlEZldOKVEZHBw4m1p18/GSJ3MIWKzft 46o3mpbMwdGPdOiMAV6g4LupVzUaLzASEqwm+Q4= X-Received: by 2002:a37:6c07:: with SMTP id h7-v6mr36565441qkc.185.1534682272534; Sun, 19 Aug 2018 05:37:52 -0700 (PDT) MIME-Version: 1.0 References: <20180818131623.8755-1-linux@rasmusvillemoes.dk> <20180818131623.8755-7-linux@rasmusvillemoes.dk> In-Reply-To: <20180818131623.8755-7-linux@rasmusvillemoes.dk> From: Andy Shevchenko Date: Sun, 19 Aug 2018 15:37:41 +0300 Message-ID: Subject: Re: [PATCH 6/7] lib/bitmap.c: fix remaining space computation in bitmap_print_to_pagebuf To: Rasmus Villemoes Cc: Andrew Morton , Yury Norov , Andy Shevchenko , Sudeep Holla , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 18, 2018 at 4:17 PM Rasmus Villemoes wrote: > > 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. > > Signed-off-by: Rasmus Villemoes > --- > lib/bitmap.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/lib/bitmap.c b/lib/bitmap.c > index 1f73b2e52186..277c9a63a5ab 100644 > --- a/lib/bitmap.c > +++ b/lib/bitmap.c > @@ -460,14 +460,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 - ((unsigned long)buf & (PAGE_SIZE-1)); Don't we have offset_in_page() helper macro? -- With Best Regards, Andy Shevchenko