Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1229370rdg; Fri, 11 Aug 2023 14:20:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVwuG//SAWZTRS00hum8udbakv7GX8Yn14CVxQM3LzjRkaiRm3uYQlViJKl9mLVI13lcmg X-Received: by 2002:a17:90a:540a:b0:268:1068:4464 with SMTP id z10-20020a17090a540a00b0026810684464mr2470873pjh.30.1691788800051; Fri, 11 Aug 2023 14:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691788800; cv=none; d=google.com; s=arc-20160816; b=i4x4y7x3Q6qOjtY7uQQEK1Sp9mJWTrOnLplPefyci9Xil3IX6+FoqXOqEEHgdYC2U2 ShwVwIn88Ca/n55htuBVv6MxDjbPcOM0c+k5w4T+hXGT758wcUPal8F5GFhgESMTkfqC 09U1IanEwUECz8Vh6vsfGAeBYGzD032u+Fn3X9RzuS07LL9EVVUdyy0VWP7GorktlK2Z bhvSkd6bnWjvvHVjOplAv/jF7MHaQmxvHaViH3G53sa8nRFKXePwFtdvd49oPlMw9Wya 2m5+fTtMxVLmVbFeD1Q1PEakV4ucS9eKMbfOxZtotx36JZnFBLY//0KHBiR9ESb+Om7J P/2w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=v6G6ZsuSoAElNftzo3kwRe5FK/2FlGxWGqeqEHPrOvI=; fh=ro7U2rHfUQa1QrJMbNMHXoybgav6jrg8IGw1NEcWGro=; b=KqKODGVijS1+1vSjpgqxZHerZXAB0m97cjq/sd06us3Qfp8HyPG6TEqmgnsN6nzzl6 eFEs5fhH92P9XlLjjIMvIyo7Z4OWK/12+EVYmJtKAKnxc8WwiPZgsoiFb7yJzrjPEIaJ VPRwu+7a9Bd0FEz1u0mNok3Lyh+vIv1xydF80Jeeo8T/YANqykaEjjL/ffVNxXK9TxBL S+8g9CSJ7pl+uAPvnrfB5VOGMrrxcWizIoDxyWl6tHwLc3Dj+Wfpg8w45YuTNof8s2V8 cvwGzi3D3uiB//SrrHzOSEUJW0DpLKhJ9v/MI0KrLoms5gXdkTCOoCi5tyGkUBkTz48Y y98w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=RxfvhmJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a17090a9f8500b00262d1b39524si3984096pjp.116.2023.08.11.14.19.48; Fri, 11 Aug 2023 14:20:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=RxfvhmJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235584AbjHKTs3 (ORCPT + 99 others); Fri, 11 Aug 2023 15:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbjHKTs3 (ORCPT ); Fri, 11 Aug 2023 15:48:29 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD737EE for ; Fri, 11 Aug 2023 12:48:28 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-997c4107d62so315550366b.0 for ; Fri, 11 Aug 2023 12:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691783307; x=1692388107; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=v6G6ZsuSoAElNftzo3kwRe5FK/2FlGxWGqeqEHPrOvI=; b=RxfvhmJg/lkv55d73lCUiQyY749TBwr/BUK/AUEdLGM175XjeImsC36EYmC4v3vvBT bePaqmfq9kimsHXkP+U1RfnmD9bOaxMjZOu6geFDBkaVfV1gmZyB1sdzg+DOa2aFOkTV 63gzTLe1RERRAPJCMtqs/k9KdWmgP1rOcqgRGjxZCDBMgD73jWsnVSzuy98u4i6RJFrn I7KQBAg/2MT086+a/CUVhrIrwa14BZ9FpVCaF3fj2CrpDbVfbHsiOrbi23redqiCuEVX poJDRIxSkJuX8yWBUyekhFO6ThUnIkgb8aLRuPChWIva3kRkJHoug0XF3Nh8YVnxeShR vPaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691783307; x=1692388107; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v6G6ZsuSoAElNftzo3kwRe5FK/2FlGxWGqeqEHPrOvI=; b=kMRgwwXPnAsS/vwqsNRH99J78JK5NVJ6Lm8RnlJj2CScsTvck5tPTxRr4MFoEZjPHh lgAuialiHQRY4PF3bmBkiGyOO0kS8/cO1zvYMaHoUPH6uS+wcScYQjR//YVwv1e3lpkD i/98NYnUlWIwx0QCH2S5dfevHUTv+5bqpV/IkaYFT1qZRSBUWfPK1YUiibnyQvhl+/K1 gtduAD5UI7EOzueqJvlzQ5k4IQYbgrvloa1GtJjsnQHIONbIuAuE8tKcaUj/3GvKm9Pj k+FcwGf2ShQUVbv7Rk0UHY9onKLoPozExjRhU0Dqe5IOH3di4yCy82m2dHF8EzWbDSp7 sQJw== X-Gm-Message-State: AOJu0YyFDwbLr4Gif2pJLJz3YLZHaiZWY0JNb/N7Ok0GWCC9KEKc2+q4 op5KXJ7p2e6T+idU0LVVMpU= X-Received: by 2002:a17:906:7488:b0:99c:1c8e:ac20 with SMTP id e8-20020a170906748800b0099c1c8eac20mr2423950ejl.22.1691783306898; Fri, 11 Aug 2023 12:48:26 -0700 (PDT) Received: from f.. (cst-prg-75-195.cust.vodafone.cz. [46.135.75.195]) by smtp.gmail.com with ESMTPSA id q14-20020a17090622ce00b00992ca779f42sm2598994eja.97.2023.08.11.12.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 12:48:26 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, Mateusz Guzik Subject: [PATCH] vfs: fix up the assert in i_readcount_dec Date: Fri, 11 Aug 2023 21:48:14 +0200 Message-Id: <20230811194814.1612336-1-mjguzik@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Drops a race where 2 threads could spot a positive value and both proceed to dec to -1, without reporting anything. Signed-off-by: Mateusz Guzik --- include/linux/fs.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 562f2623c9c9..21c8f8ae014d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2613,8 +2613,7 @@ static inline bool inode_is_open_for_write(const struct inode *inode) #if defined(CONFIG_IMA) || defined(CONFIG_FILE_LOCKING) static inline void i_readcount_dec(struct inode *inode) { - BUG_ON(!atomic_read(&inode->i_readcount)); - atomic_dec(&inode->i_readcount); + BUG_ON(atomic_dec_return(&inode->i_readcount) < 0); } static inline void i_readcount_inc(struct inode *inode) { -- 2.39.2