Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1426767lqd; Thu, 25 Apr 2024 15:40:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7NkyXFtWpyTlUt5IE103xlMapeO7rG39ZDSMPetuojubebxF1Y5jM76ji+Bwc1T7bWM0znSRWOCXnPal7ohw18xAXDAmY0/pP6+icfg== X-Google-Smtp-Source: AGHT+IEwxlu8XZpf9UUmmWYID4SzBXTvi5DWrg6A+Yg2agPOxh3N0PYn0h12PxxQt71wbhRY9wQ3 X-Received: by 2002:a17:90a:7895:b0:2ad:a5d2:8e2d with SMTP id x21-20020a17090a789500b002ada5d28e2dmr1139448pjk.14.1714084844593; Thu, 25 Apr 2024 15:40:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714084844; cv=pass; d=google.com; s=arc-20160816; b=dhXeiR8lt0ygaWLmLx4s5vzf+AEemdDK+yFm3hiT2xI88ycAEYb2lQt6JQuVv8QVCd uYqzDMMJpQbXVquwW8PBr0qcc3RrIgG5jtOtf3+v+xgEn6nilEzzq4+Js03qk4y7M52X /z1L4wwhstVFAMOM/MBNcgyP0pRDbpNDKm1yI7iXTgeSi2di56xR1uwDIPDlDjO/yhKq Nvjtu/OWV7x/Fc8V59Mgfrxnb+kkC7I7dooAfxcFXpAwyBJYXbNszV+D+YkPKYheUlGa fRlLMikeAfb/xd/4RrpG7vwTJebbdLdYujm1zuA9UGOaoaB4Q9B1/4JmXbNBsnuKlcwm Cveg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Pv6DAoPFFNrD4sYIPF/agyqOANkVbxxZ+lZCZEZ+GiM=; fh=AIO4L9BgF/uxqGHaeLXRSB/7CdQO6fah+i8OVCJYhUk=; b=PRypwGUeslkjeyK4pir8I6+sRPTrTgU3jOEZRGcA2dskSQtQxUB2LKlGxyhhIGS3Xd Hd7mtZIP1AsNvlSmp9XAN0tRsU/lIRE/SuldGKKr6PRumqA4pmgA/tpraIxePHEfiA6p 3rzy98e0a0/aG2hddKViroxSo9ygXVxlU8/oaNmwU6wTyFNQa3AerSPuu0lE7zavSi8x vB64SYulIuopw4vqL97N/PIMhKHc76vJV0kABBc0lSwpvqaTfBC578XlIa2u9SEKIHHb MtUV0ShO5cgD5VPdKEgwzQDVQC/Yzde/GlFQmoSfl+fdaMfBVoENkMpXB7nhiKGUuOYy ZVNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=JrN+gwGB; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-159328-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159328-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b23-20020a17090acc1700b002a3be34832fsi14024836pju.34.2024.04.25.15.40.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 15:40:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159328-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=JrN+gwGB; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-159328-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159328-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3D28A283EF9 for ; Thu, 25 Apr 2024 22:40:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE7381482ED; Thu, 25 Apr 2024 22:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="JrN+gwGB" Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 815792599; Thu, 25 Apr 2024 22:40:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714084837; cv=none; b=i9A/SDT5YQ5u0WTJ4NKvBb4oQoLxKG30QiQVnjEGP6aFd0DHCFgo52LKDN2xaa9kcoC6k1OvyXek8mSqsp7Z1B2W9FPWp7HSKi/AZcGA3H06azeDvfEo4iAymb7TynhMPARkqtzxKGBZzSSs6n+79eEVo63cbG/rTN6xcfkRL2A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714084837; c=relaxed/simple; bh=isimwcOHdDK7dQ5J/GY/2fBT8r4/NY8PJ8OszygoMX4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q4aMOEyj39BtUTL457CtifU6Ma1pb6AEd8+zw6MryGIcgQlH+CYJ+ZMOItEI4YSFIYjgY9FwMr5iI/ttUXvg/kHIoZtdGOrnC4XWC1hhvt0OD/CjmZoFeONRBneS+rQiChWE1cE8+q6UZbg5lB/s3ZRvPnnqUDvkwcPIb2pgomY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=JrN+gwGB; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description; bh=Pv6DAoPFFNrD4sYIPF/agyqOANkVbxxZ+lZCZEZ+GiM=; b=JrN+gwGBiCeml7wT9b6Ytx+8zr E199uP12fHkIKlQBzuWwF3kTvVpMlFuwd5s25SPo+4NkOMRvOr2Imy6xxJJF+njOuGptf8Zew0Ibq KPjc39y8562tf4ByOhadWH7GuD1gVuM/dqzfYIrpG8Tk/3SOHdFDjAWP4tRmTTZFIb06BzcWIbp/4 tlRQRwmmabiIUYsZgpe6gtzHLjpAP7MLAxo2DDaJ65Ar8XiM7nHR40HOtJ4/3WYmDY6H/L9DPs1rC Bl93lsDBs8NkuMqNge2MOiiMM7JSM+k1VTdlNjlGa+C+rM/tCKK6kFFrOAuAXEFAaCT73kRxIkhzH dSMCCz5w==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1s07lY-0000000AV5t-1zP9; Thu, 25 Apr 2024 22:40:32 +0000 Date: Thu, 25 Apr 2024 15:40:32 -0700 From: Luis Chamberlain To: Zi Yan Cc: akpm@linux-foundation.org, linux-mm@kvack.org, fstests@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, willy@infradead.org, hare@suse.de, john.g.garry@oracle.com, p.raghav@samsung.com, da.gomez@samsung.com Subject: Re: [PATCH 1/2] mm/huge_memory: skip invalid debugfs file entry for folio split Message-ID: References: <20240424225449.1498244-1-mcgrof@kernel.org> <20240424225449.1498244-2-mcgrof@kernel.org> <17447911-9578-45B2-A601-28CD0C5036D4@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <17447911-9578-45B2-A601-28CD0C5036D4@nvidia.com> Sender: Luis Chamberlain On Wed, Apr 24, 2024 at 09:03:51PM -0400, Zi Yan wrote: > On 24 Apr 2024, at 18:54, Luis Chamberlain wrote: >=20 > > If the file entry is too long we may easily end up going out of bounds > > and crash after strsep() on sscanf(). To avoid this ensure we bound the > > string to an expected length before we use sscanf() on it. > > > > Signed-off-by: Luis Chamberlain > > --- > > mm/huge_memory.c | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index 9e9879d2f501..8386d24a163e 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -3623,6 +3623,7 @@ static ssize_t split_huge_pages_write(struct file= *file, const char __user *buf, > > char file_path[MAX_INPUT_BUF_SZ]; > > pgoff_t off_start =3D 0, off_end =3D 0; > > size_t input_len =3D strlen(input_buf); > > + size_t max_left_over; > > > > tok =3D strsep(&buf, ","); > > if (tok) { > > @@ -3632,6 +3633,14 @@ static ssize_t split_huge_pages_write(struct fil= e *file, const char __user *buf, > > goto out; > > } > > > > + max_left_over =3D MAX_INPUT_BUF_SZ - strlen(file_path); > > + if (!buf || > > + strnlen(buf, max_left_over) < 7 || >=20 > What is this magic number 7? strlen("0xN,0xN") as the minimal input strin= g size? > Maybe use sizeof("0xN,0xN") - 1 instead? Sure and I forgot the fixes tag, will send a v2. Luis