Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp118973ybi; Wed, 29 May 2019 17:54:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwanlc4R7hQJtcmtoYi07ITGmyoDMnhvKZA0t0dFGgjwAfrIb0Sp7gcT+UpACs1FWoKSUfO X-Received: by 2002:a17:90a:b78b:: with SMTP id m11mr634537pjr.106.1559177699684; Wed, 29 May 2019 17:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559177699; cv=none; d=google.com; s=arc-20160816; b=b9+Ux5zr7wsGl73YLWZ8WbN7nKNjJprgehESMIWA6byyk9hdz2g57/AOA2L9mjd9Ms Kf3CR8TMhem/OAMJxhMe/c6Mw/8AFuu0RFeqq5iwcgCrWfCnhXayvoGaPFE9wRQxzUu6 Ufc7PyESUIpj7edhy1tPLfksKxQuIpGXa94Ve5wAtfI8ieA0o/wgHhskWJzgSeoY25Et IDLkCNVL2lzUZnA+BgYRGhj6snpEqanqA7qsZHenORFD31y9U3mTajvwjWVmo4ANRtpT 9BGzRSZxlsA+qks08Vya/JaZqqKPR4eTLjQiafrQXLyZ/a2Jt3bWYCSCQJn5aixCk4QP SJEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=d6X4/k5B5WeQgyIvpn8Af86NqovFLF22qTA1Y2V4Fe8=; b=TgWkjBN7+no+VGoKkcCUQ+wb46hHzbu11I2U346/MSvw0DF4qQoyCeQaqhnNPlqNf6 xN+D5ZjI45W9kxoPH8NFCYMok567dIeQr2wAMN+nOETEtR3dCqNhWutynd2LeHNUF9dC QXzolfyEYuGCrzs3xo4I+vsvsZyDbmeLVKbFnIy1x7OgoWO2NJIG2O+pEfSIvtVyqEup tgnqtUAkvv1vUGykvEuvZXUBqLF1Stg30v/Am76ojG6tvgqZRbOM7jIyJoYhbhzQgMkR svc+qOVqJafD8cdUhJdeBGrrY/2tGkVcfJ/QPFjX5zd3teHOElSXuaxbOnqOOyzfjUYK gb1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ax2EXMsd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y18si1419252pgi.78.2019.05.29.17.54.43; Wed, 29 May 2019 17:54:59 -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=@google.com header.s=20161025 header.b=Ax2EXMsd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727237AbfE3AxZ (ORCPT + 99 others); Wed, 29 May 2019 20:53:25 -0400 Received: from mail-yw1-f73.google.com ([209.85.161.73]:47712 "EHLO mail-yw1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727194AbfE3AxY (ORCPT ); Wed, 29 May 2019 20:53:24 -0400 Received: by mail-yw1-f73.google.com with SMTP id y18so3911915ywy.14 for ; Wed, 29 May 2019 17:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=d6X4/k5B5WeQgyIvpn8Af86NqovFLF22qTA1Y2V4Fe8=; b=Ax2EXMsdAnoEHIrqzhP0Cv23VlEaDoSoO1OWqhvxtcuBXmnYYLbiiBAZQlVXUUtGgA i6w+G4d54N8mfV0D6KY3vURUd55d8xA1pwqYEpTzjK68EmxEOCRJVDhq648b4GXT1jGV 3YrMacqCMm6wtkWM9ach4dG7xfETTseNfVw9UM/pxIHth0Ji7tonp1P9tLbqoqqtynbi DiENSJNzIdEipIykCMGLgC1Nz8YKxon3Gno9T6HkP2TBj6bY9GFxNm0etPi64anLqTnl aFpqLIUEQL5Pswsuq9dgOrW+1PKzioUiwtMYbgzR/a96OB4IOOCPkunrKKKeoQnMXWxu 4Y7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=d6X4/k5B5WeQgyIvpn8Af86NqovFLF22qTA1Y2V4Fe8=; b=iCZLoMm3fldiREIbpjBtJgpUI1Jqfcg/DZ7zcI/0cgdpUy/sPL1N8aewvaxzGnxAcX W9oXnDluKoZC0K8hIBELKAI/6JxQT9prPXL5M8klXcNfO9aF48c5UfK9DFsOZ1WStPWf 1hh8nsysnffjNFqq4FddUYH505Etx1g4xFN0HN+ht+OT9tz3ABfpABEBPM8Z2it9+ca6 c7+lc1xHkOFqNy7nFi4C/1vxOgGiaNoxSd9KviMZ7ujweOAR313q84dw2r7fJ1CyI5QE dywo5IR0w6i4XDjBjTzGq3MYrxJmIbbthzIbtB9xqH3buT1xaxlEJMpS5qvpUFJY/ZOb AnQg== X-Gm-Message-State: APjAAAVSBz/8b0YkaN2OLiPCnj1J3+akNFTeNdvKTLW+/bxZHDv/Kt3t XfuzN5g422rMrIeTKtO4wsStJdwD4Tw= X-Received: by 2002:a81:300c:: with SMTP id w12mr555304yww.57.1559177603199; Wed, 29 May 2019 17:53:23 -0700 (PDT) Date: Wed, 29 May 2019 17:49:04 -0700 In-Reply-To: <20190530004906.261170-1-drosen@google.com> Message-Id: <20190530004906.261170-3-drosen@google.com> Mime-Version: 1.0 References: <20190530004906.261170-1-drosen@google.com> X-Mailer: git-send-email 2.22.0.rc1.257.g3120a18244-goog Subject: [PATCH v3 2/4] f2fs: Fix root reserved on remount From: Daniel Rosenberg To: Jaegeuk Kim , Chao Yu , Jonathan Corbet , linux-f2fs-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-team@android.com, Daniel Rosenberg 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 a remount, you can currently set root reserved if it was not previously set. This can cause an underflow if reserved has been set to a very high value, since then root reserved + current reserved could be greater than user_block_count. inc_valid_block_count later subtracts out these values from user_block_count, causing an underflow. Signed-off-by: Daniel Rosenberg --- fs/f2fs/super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 912e2619d581b..359fd68509d16 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -213,7 +213,8 @@ void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...) static inline void limit_reserve_root(struct f2fs_sb_info *sbi) { - block_t limit = (sbi->user_block_count << 1) / 1000; + block_t limit = min((sbi->user_block_count << 1) / 1000, + sbi->user_block_count - sbi->reserved_blocks); /* limit is 0.2% */ if (test_opt(sbi, RESERVE_ROOT) && -- 2.22.0.rc1.257.g3120a18244-goog