Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5430475pxu; Tue, 22 Dec 2020 17:38:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJw86OWhvOCIIALOMG0P8mzmzwXY+Vt4IY+pfrVwBlciF9RsQ/8tR2qbqshN48nLhVJsUzgU X-Received: by 2002:a17:907:3f93:: with SMTP id hr19mr22763123ejc.235.1608687495958; Tue, 22 Dec 2020 17:38:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608687495; cv=none; d=google.com; s=arc-20160816; b=yUtXeHkYg3GhhPqltyhLLZ+D5vxgDUw5Nfm6DG/3hU5uOkY2Aep8qpYR0gvpEU3eyQ H5ZORszmBTCbuyTsej0+S7zQlsYpIqPhWw1/6E5ajQfveZCqj2bh02vnPXrmVLdFIuR+ bb527YfjmlwwApL3bMpMkeOYcJ9KOJFL2JI4D7Dg8eJmFbh+d3v0LkRLSFVLQPcYpxrW 1CcK9h13uNEfvoJYbGo4FTcGDWq7nQ/BrTf/UxGxgrJIpTzQt2cturUh59Z5ZgEXMwER JUpbZQyO6vXPYfy94D7HAj+bDV+/oVGf5Hzv+1egrpduw2ubTXA3W9hZsD1tVJGTu3fi 7OwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=xgELD84IXH8sR9xug4LL9S3pwjjj77Cfmrz7c6076Fw=; b=S5XaIueZdXFgsYYhqbUOzEUQvXOtlXIJURhY6Npr8kXtHbOj/KTPndwYzALAlEVrUM lGI+th3mfxaCOnoduDOBGrwNBw1iPSn/Y+QuFPc8o019iJ+VXclkZ8l4rpKxf0+8O4dy 7henz+Ju5XSumflhsEFdyonBJ8XSDxVk2fBNfjy5SIU37VsC83V0yR7twtbztPw3PEpd sDFA+c+yQuK/afch5B+VpOCsbvZ8CR4uSaHXIi1Pr3UR86w54urcvTSK2qXJ6o2RPf5Q N3SsTWyNC7pfFHPW0sTFjVWuBHm5hg7E3JiChPT+wybitIibBvoINhIDavDmg7ViDcS3 B9sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=186twYlo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f20si13038964edy.12.2020.12.22.17.37.53; Tue, 22 Dec 2020 17:38:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=186twYlo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726361AbgLWBgP (ORCPT + 99 others); Tue, 22 Dec 2020 20:36:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:34180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725931AbgLWBgP (ORCPT ); Tue, 22 Dec 2020 20:36:15 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 74B432253D; Wed, 23 Dec 2020 01:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608687334; bh=E2/QufhUm5QbmYYkwMorAN26mVOwdusNezXD+EAiCGE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=186twYlo93vGO50+xqZTCkfaB/dX2+7v+d92AN2wFsjVS8riTovtFkjJnMgPrqrjZ 3ZfzsfU5hKw/vVM+Y9a459VBhSWC3jdGogKAF+SSxK0QbgaPYaTtMDSf7bz2pPIrvj 0jCuFeanGFCE8O3q8qjosQvOyINhV7KNgXBP7FLg= Date: Tue, 22 Dec 2020 17:35:33 -0800 From: Andrew Morton To: Randy Dunlap Cc: linux-kernel@vger.kernel.org, Jens Axboe , Toralf =?ISO-8859-1?Q?F=F6rster?= , linux-mm@kvack.org Subject: Re: [RFC PATCH 2/2] mm: readahead: handle LARGE input to get_init_ra_size() Message-Id: <20201222173533.c9e28416835d7487b0e28cda@linux-foundation.org> In-Reply-To: <20201220211051.1416-1-rdunlap@infradead.org> References: <20201220211051.1416-1-rdunlap@infradead.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 20 Dec 2020 13:10:51 -0800 Randy Dunlap wrote: > Add a test to detect if the input ra request size has its high order > bit set (is negative when tested as a signed long). This would be a > really Huge readahead. > > If so, WARN() with the value and a stack trace so that we can see > where this is happening and then make further corrections later. > Then adjust the size value so that it is not so Huge (although > this may not be needed). What motivates this change? Is there any reason to think this can happen? Also, everything in there *should* be unsigned, because a negative readahead is semantically nonsensical. Is our handling of this inherently unsigned quantity incorrect somewhere? > --- linux-5.10.1.orig/mm/readahead.c > +++ linux-5.10.1/mm/readahead.c > > ... > > @@ -303,14 +304,21 @@ void force_page_cache_ra(struct readahea > } > > /* > - * Set the initial window size, round to next power of 2 and square > + * Set the initial window size, round to next power of 2 > * for small size, x 4 for medium, and x 2 for large > * for 128k (32 page) max ra > * 1-8 page = 32k initial, > 8 page = 128k initial > */ > static unsigned long get_init_ra_size(unsigned long size, unsigned long max) > { > - unsigned long newsize = roundup_pow_of_two(size); > + unsigned long newsize; > + > + if ((signed long)size < 0) { /* high bit is set: ultra-large ra req */ > + WARN_ONCE(1, "%s: size=0x%lx\n", __func__, size); > + size = -size; /* really only need to flip the high/sign bit */ > + } > + > + newsize = roundup_pow_of_two(size); Is there any way in which userspace can deliberately trigger warning? Via sys_readadhead() or procfs tuning or whatever? I guess that permitting a user-triggerable WARN_ONCE() isn't a huuuuge problem - it isn't a DoS if it only triggers a single time. It does permit the malicious user to disable future valid warnings, but I don't see what incentive there would be for this. But still, it seems desirable to avoid it.