Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1073294pxk; Mon, 31 Aug 2020 09:05:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsfZGsBKHePXBEuVmUyzMvMuwcgg53+tJ04/ifNXx0j6yFVmCnhVOQJ7W7kehDq9sN3OW6 X-Received: by 2002:a05:6402:17b6:: with SMTP id j22mr1725311edy.377.1598889900708; Mon, 31 Aug 2020 09:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598889900; cv=none; d=google.com; s=arc-20160816; b=kq8L1v5L31RYX5YAJ28dVOoa8imm6GcQ/IUziAG0F6lvyV/bA2Vt/0r+cWS60UsjVO 1PrGMPSW1ScThPURrp39CQayV18k64JWkGhrFktU0KkiOV5lG7joTfbzbREiFn+gzTWX u69bqsUnuO5lI5Frrwqm35Dbgj2KltvWw28aRy+CtSUUR/KjQh/Ubs0u2RDVROa7+Ovg CybcXb8jkHwFMWzZVf9hmhtuI0mZC7DstNxNsUBYqcagfSPJF5+FS/M7+cLm+Vq3wick 6l9QxtQAPsOIsjx1OGWM2BV3accymq0xQHBfntIewzlJHLK2cWHos2KKDPqygujI73Yl jXBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=szyBZmXmGTfhNbvEwHNrOEoyR6ZVqLq4aSXH4RxuP/w=; b=0v5Jk/KZCYMxAwQhjm+Tm353nS3wjLcOEMJPeOQAg6zlBx/PORUX1eNWg09bemlDPi neyJXy7SNrcEhcYZVrSAMMe56PfG35VVQZiiSpzphnvHcMlkYoyflENW1L5fLW2sPWmw 6lhmeZ10jamm89+JvUfCF7Mcax6f+2LJ7DqfI08z98vVLKxr8eqse+Im51YdWy8ghWWm Zfimt8+Ip4O6klqrDjaDLil+SotiBd5fgrtsXSSAYLTM7t7zSmilWIZCn140Q4I+RhFF K1zVIfoF/vWckVEj6Fdakjh4byYuE30No5Tt95RRRPhDgv9GHO3oUnSowOgxY18zk6PL efsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=NuUGQOHx; 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 gz7si3542259ejb.441.2020.08.31.09.04.37; Mon, 31 Aug 2020 09:05:00 -0700 (PDT) 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=@lca.pw header.s=google header.b=NuUGQOHx; 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 S1728228AbgHaQCH (ORCPT + 99 others); Mon, 31 Aug 2020 12:02:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728165AbgHaQCE (ORCPT ); Mon, 31 Aug 2020 12:02:04 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3326EC061755 for ; Mon, 31 Aug 2020 09:02:04 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id t20so5081115qtr.8 for ; Mon, 31 Aug 2020 09:02:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=szyBZmXmGTfhNbvEwHNrOEoyR6ZVqLq4aSXH4RxuP/w=; b=NuUGQOHxyfqfMJUN82zrksWb8lPBil57bkrhwOwi9HrnrM305tAW7ZTvinRCmW8ntx GDwP698CZW7qroPU3cIlSkjc0xqDq/mYioEzHXYWx1q68VaVBgpKJ4T+1CnZXhGa9Kqe jSq2fj5vtbnRlsp1bKweEpUH3we26uOqQm4JhXtxt3HVM9bhoUcLdfKYlQPrYJWQe2DO 3puXqUK9qh1zQNZDKGIvz9Q6FBu2ypq5LCNxHhn/NZQjW5Bq8i30dP1uKSQtEqub3gcr 7qw/ly98IFJafxtRe3kU1V4dS2ww1hCzbFJtsNqOrHO8AarB1BA7BYm3VYBuZU9COGH6 ZuYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=szyBZmXmGTfhNbvEwHNrOEoyR6ZVqLq4aSXH4RxuP/w=; b=mC/rs6SSgDiNRSavFzAp2qjL2TqciFV8TrKrMajPUU6xdCQ4Q1Hiu11jxH4r/UwJgi 50tZYsU2HrzcSpw5+nkslWKgD+HmNLe0yamcUimaPEAtq8DFkPKCrEcxKKCkm18V7zMV uPUcLwifDiREJGsDZEfHkVnvGNlZFAlB0s+1X1ouQLwsQzujWJPfVBMb9Zl4lTVKv9tT FslW//AqdNwDssKLps8yL40hdJOJraedqWBw5+Qi70yJdlMysVV5rOKScCdePJvC9Tbo 53xIsfSgetSJqpnf+/uWWeZJMiR0Jc1MHJp1oapXuTPNJg4qhH5r/sRIEkmS6qo76G+m K+zA== X-Gm-Message-State: AOAM533mos8RRnqo/vCTl3lJunSlndYfmudTmyu/TnuPmxkWfleOsquu Z3/3Tiffda8QoJ6TLRYxy0GWFg== X-Received: by 2002:ac8:142:: with SMTP id f2mr1918414qtg.191.1598889723060; Mon, 31 Aug 2020 09:02:03 -0700 (PDT) Received: from lca.pw (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id g64sm7050652qkf.71.2020.08.31.09.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Aug 2020 09:02:01 -0700 (PDT) Date: Mon, 31 Aug 2020 12:01:55 -0400 From: Qian Cai To: Eric Sandeen Cc: darrick.wong@oracle.com, hch@infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] iomap: Fix WARN_ON_ONCE() from unprivileged users Message-ID: <20200831160154.GA4080@lca.pw> References: <20200831014511.17174-1-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 31, 2020 at 10:48:59AM -0500, Eric Sandeen wrote: > On 8/30/20 8:45 PM, Qian Cai wrote: > > It is trivial to trigger a WARN_ON_ONCE(1) in iomap_dio_actor() by > > unprivileged users which would taint the kernel, or worse - panic if > > panic_on_warn or panic_on_taint is set. Hence, just convert it to > > pr_warn_ratelimited() to let users know their workloads are racing. > > Thanks Dave Chinner for the initial analysis of the racing reproducers. > > > > Signed-off-by: Qian Cai > > --- > > > > v2: Record the path, pid and command as well. > > > > fs/iomap/direct-io.c | 17 ++++++++++++++++- > > 1 file changed, 16 insertions(+), 1 deletion(-) > > > > diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c > > index c1aafb2ab990..66a4502ef675 100644 > > --- a/fs/iomap/direct-io.c > > +++ b/fs/iomap/direct-io.c > > @@ -374,6 +374,7 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length, > > void *data, struct iomap *iomap, struct iomap *srcmap) > > { > > struct iomap_dio *dio = data; > > + char pathname[128], *path; > > > > switch (iomap->type) { > > case IOMAP_HOLE: > > @@ -389,7 +390,21 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length, > > case IOMAP_INLINE: > > return iomap_dio_inline_actor(inode, pos, length, dio, iomap); > > default: > > - WARN_ON_ONCE(1); > > It seems like we should explicitly catch IOMAP_DELALLOC for this case, and leave the > default: as a WARN_ON that is not user-triggerable? i.e. > > case IOMAP_DELALLOC: > > return -EIO; > default: > WARN_ON_ONCE(1); > return -EIO; > > > + /* > > + * DIO is not serialised against mmap() access at all, and so > > + * if the page_mkwrite occurs between the writeback and the > > + * iomap_apply() call in the DIO path, then it will see the > > + * DELALLOC block that the page-mkwrite allocated. > > + */ > > + path = file_path(dio->iocb->ki_filp, pathname, > > + sizeof(pathname)); > > + if (IS_ERR(path)) > > + path = "(unknown)"; > > + > > + pr_warn_ratelimited("page_mkwrite() is racing with DIO read (iomap->type = %u).\n" > > + "File: %s PID: %d Comm: %.20s\n", > > + iomap->type, path, current->pid, > > + current->comm); > > This is very specific ... > > Do we know that mmap/page_mkwrite is (and will always be) the only way to reach this > point? I don't know, so this could indeed be a bit misleading. > > It seems to me that this message won't be very useful for the admin; "pg_mkwrite" may > mean something to us, but doubtful for the general public. And "type = 1" won't mean > much to the reader, either. > > Maybe something like: > > "DIO encountered delayed allocation block, racing buffered+direct? File: %s Comm: %.20s\n" > > It just seems that a user-facing warning should be something the admin has a chance of > acting on without needing to file a bug for analysis by the developers. > > (though TBH "delayed allocation" probably doesn't mean much to the admin, either) I agree with your suggestions. I'll submit a new version.