Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp803538ybc; Tue, 12 Nov 2019 09:25:23 -0800 (PST) X-Google-Smtp-Source: APXvYqyYmxVtmt4qW/ZtTjEGM2mCB301epAuA4GWtkYXKF5FyxCoFVra2gup7srGpDDe1fbuH/dD X-Received: by 2002:a17:906:1d01:: with SMTP id n1mr28712445ejh.95.1573579522899; Tue, 12 Nov 2019 09:25:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573579522; cv=none; d=google.com; s=arc-20160816; b=wx6fq0RKXCKWmcsKkqyDBODB/R2RRCg9aeUbyuXuTjpJV2wPNUR45P2llxcNLqu3Vf 7JenCNEpkii44aRgd3NfjsyEF2TCYUbEqDmQDAXsvcZhzohXR24G3QE19IFgX0DcC/Af PlfWOLTqwNWeQh7vyQ0tq6v+nSDrE8YD7qAsTPrMaCndskDm2t+f7GaRto1yWAMV/z+K 4GuBdeotD0gUtUc8U8fifM6pQZl3/VFOosBmhIrestEEdyIZTSjDMk13HZNte9VZFmYu SvBDcr68QwnhnqSgVyQRcqJ5W6jeN7IsKPi41Akq3H4PRTPUpFLWCW/92A4nB7eokYiP 4U3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=XShByMLu//cYaYZBKvqGtxFWH4UjDRbybOVR95jGz/I=; b=J1zXVt6yKRuZz3Z0zKuIPkFm3r5QntAU0+l07OTPFnHfyngvujfOMrbiCeTDAbIEmu 83jgypei1XBVXlc+Ridv+8ABLxxUG0lqECCB8EYPpI1xRpUy7hDsxqw2ZrpLB9gTCidu DTibFhy7yaqQ2piaNjPp3IkKnnMRNvIE7zY1zApO56jBFUMA0PCuwdkkHPJGgwFRHu5X kRn4O458Nwk3rUkpD1hrsk8pq357iNjBssscqoaJedLKs/iuvK6SCm8U54VmbnOZOvUz MtMCnD8/2Lpr7zOEz2wD7PfPvQIfwfjW2rCRTITQJnOgcu+d84NMC5mUnCuaFZJoPOPZ xmjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=MNvkK6ga; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w56si13877437eda.376.2019.11.12.09.24.58; Tue, 12 Nov 2019 09:25:22 -0800 (PST) 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=@linux-foundation.org header.s=google header.b=MNvkK6ga; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727476AbfKLRX4 (ORCPT + 99 others); Tue, 12 Nov 2019 12:23:56 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:37992 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbfKLRXz (ORCPT ); Tue, 12 Nov 2019 12:23:55 -0500 Received: by mail-lj1-f195.google.com with SMTP id v8so18725293ljh.5 for ; Tue, 12 Nov 2019 09:23:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XShByMLu//cYaYZBKvqGtxFWH4UjDRbybOVR95jGz/I=; b=MNvkK6gaA2ornBJfgB8lmMgtKjS5hIKoXiHCGGLj7vU0zf0dCWiBna4ovnMMdHCGhH HsHFPAgdTnHSJhls7WKv0HtJ6tf4Mdstu5O/Ru9eMp90WQkrRwW9bX+/zXWgLjTgzkr9 iQksID0zMw01OIpz2Z4X0yD1w6oNJb3f8ASss= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XShByMLu//cYaYZBKvqGtxFWH4UjDRbybOVR95jGz/I=; b=md4x/OcU8H9fflUT6SbBhu2Xh9Ce5sULoOahzCRIfUsd95DEXt31PfQBjC5Qs/iBJJ Th4vzuVzVIL7FrK7eP2k8j9Gu9oP1Xo6FnW3Vqbd5trARjJOdUUOxXYEArUed45Ssu3h Qcnj79HD7vTzPxNwRFzAWOc+9DIhJcE3F6ZZ9Q8UcrnE4VtnuEL8Y3+P3lKNxHxNlc4S 88kKJOgYay1G9ykcCGBMji2N42a3qS2Casp5w5IIff5kW5OcfigI0ttd57G4ijDoSzHE 7FEW0F3BnA58mjLFHtL/w4nVd7qJ43XVyr9frjhm6QgvMhl68iQCzZ/mMYuLugRmg+bC RE3w== X-Gm-Message-State: APjAAAV4/Rs8nZ9VGX7k4lCUerZ2nndcfiOuivvTf6Emcgu9B5stJQgl /Rc+gxa4v/UXRt8pLGb9BCFRd912LgE= X-Received: by 2002:a2e:9b89:: with SMTP id z9mr21487668lji.185.1573579432613; Tue, 12 Nov 2019 09:23:52 -0800 (PST) Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com. [209.85.167.52]) by smtp.gmail.com with ESMTPSA id m20sm2700607lfj.35.2019.11.12.09.23.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Nov 2019 09:23:51 -0800 (PST) Received: by mail-lf1-f52.google.com with SMTP id j14so4912394lfk.6 for ; Tue, 12 Nov 2019 09:23:51 -0800 (PST) X-Received: by 2002:a19:4949:: with SMTP id l9mr6614232lfj.52.1573579430925; Tue, 12 Nov 2019 09:23:50 -0800 (PST) MIME-Version: 1.0 References: <20191112165033.GA7905@deco.navytux.spb.ru> In-Reply-To: <20191112165033.GA7905@deco.navytux.spb.ru> From: Linus Torvalds Date: Tue, 12 Nov 2019 09:23:34 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: KCSAN: data-race in __alloc_file / __alloc_file To: Kirill Smelkov Cc: Eric Dumazet , Al Viro , Alan Stern , Marco Elver , Eric Dumazet , syzbot , linux-fsdevel , Linux Kernel Mailing List , syzkaller-bugs , Andrea Parri , "Paul E. McKenney" , LKMM Maintainers -- Akira Yokosawa 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 Tue, Nov 12, 2019 at 8:50 AM Kirill Smelkov wrote: > > The same logic applies if it is not 2 processes, but 2 threads: > thread T2 adjusts file position racily to thread T1 while T1 is doing > read syscall with the end result that T1 read could access file range > that it should not be allowed to access. Well, I think we actually always copy the file position before we pass it down. So everybody always _uses_ their own private pointer, and the race is only in the "read original value" vs "write new value back". You had a patch that passed the address of file->f_pos down in your original series iirc, but I NAK'ed that one. Exactly because it made me nervous. > By the way on "1" topic I suspect there is a race of how > `N(file-users) > 1` check is done: file_count(file) is > atomic_long_read(&file->f_count), but let's think on how that atomic > read is positioned wrt another process creation: I did not studied in > detail, so I might be wrong here, but offhand it looks like there is no > synchronization. Well, that's one reason to add the test for threads - it also gets rid of that race. Because without threads, there's nothing else that could access - or fork - a "N(file-users) == 1" file but us. > So talking about the kernel I would also review the possibility of > file_count wrt clone race once again. See above. That goes away with the test for FDPUT_FPUT. > About "2": I generally agree with the direction, but I think the kernel > is not yet ready for this switch. Let me quote myself: Hmm. I thought we already then applied all the patches that marked things that didn't use f_pos as FMODE_STREAM. Including pipes and sockets etc. But if we didn't - and no, I didn't double-check now either - then obviously that part of the patch can't be applied now. Linus