From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECA4AC34026 for ; Tue, 18 Feb 2020 10:29:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AB31222527 for ; Tue, 18 Feb 2020 10:29:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="FzFE0W+U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB31222527 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 557E76B0003; Tue, 18 Feb 2020 05:29:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 508E46B0006; Tue, 18 Feb 2020 05:29:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41E276B0007; Tue, 18 Feb 2020 05:29:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 273656B0003 for ; Tue, 18 Feb 2020 05:29:40 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B4AFD824805A for ; Tue, 18 Feb 2020 10:29:39 +0000 (UTC) X-FDA: 76502876478.11.humor74_7161545c6ed1e X-HE-Tag: humor74_7161545c6ed1e X-Filterd-Recvd-Size: 5011 Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Tue, 18 Feb 2020 10:29:38 +0000 (UTC) Received: by mail-lj1-f177.google.com with SMTP id q8so22244585ljj.11 for ; Tue, 18 Feb 2020 02:29:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=s+I8pj7DDW7+MEIcYQaGsLXCKLqSSyhyC6U6vjGcY3Y=; b=FzFE0W+UiHz1mbo6S9YKAeko2ypDGCUCA9ezE4SgAQI+9W3ZOhB7sCDgtSRGsbtiwi WHZsz3Ox+UF79hDY/VMkWmHo8Ylh6afm7d6jEMM4QkPq8OxyIbGj8kaVffWRHnB9Z+gd bDwvsnrR7OxysvPw6GY+SYBGvFfHxfqSAfiYwoKx/bHuUYCBpPHjG/TBRUB4sKfDohAb ajJ6baDqYQgGGcVaKMuzuzxKAHyhP11EuHwX2aObJUIy7DDpX+zlSF72Sby7L3f7qQyo ypJmiBrIUWebmMoik0zRHK+cC4QiX6NBnxcTPdyBUAIpfG219xIdk/K0+0N/PnViW+8i hTAg== 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:content-transfer-encoding :in-reply-to; bh=s+I8pj7DDW7+MEIcYQaGsLXCKLqSSyhyC6U6vjGcY3Y=; b=VNIshL5XZFkdqQhxcBF5H1AWxrQMByE6R9Mz8x5q2tlBmnjslCGfBrZgpjZeOtdyTJ wIvQKeczD8F/Cq7UaGvECPy7Uf+GP92/MDSFx/cOoIvitC91kxHRkraU+HKC+H4kzpUg IJYtG5/Xl5LAHKJB886NYEWb/BTZl4I+XjMQq5og6bwpdv1T/+gUNyCtQH8Mb0yo27y4 w5O583ry5XN9BEcKOAXq94DnTYRL/VmdGd2jr9BKzdAyxgV0xzKx3bWKjfZkUwv790dR eRm3UiOBMKarmwwMmMfEx8J4mXXeooVluIGE28KDS/Ij428rODJtUY1YzM95BPtCM/j5 Q73w== X-Gm-Message-State: APjAAAVnECUgYKr8PgtO1zj5xi1jxZS1DwBSDnDVRdL519AGg+39g5HH it6O/VE03F23FfWJyE4fUYAFqg== X-Google-Smtp-Source: APXvYqx7w7kDrGAiOADdb7ykxRBSJpPOsXY00e27KzXbWnE6fz0tXD7YeabOs3OfrMDVtrtRpo9D/Q== X-Received: by 2002:a2e:a551:: with SMTP id e17mr12742787ljn.86.1582021777270; Tue, 18 Feb 2020 02:29:37 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id a10sm1922743lfr.94.2020.02.18.02.29.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 02:29:36 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 1C99A100F9D; Tue, 18 Feb 2020 13:30:02 +0300 (+03) Date: Tue, 18 Feb 2020 13:30:02 +0300 From: "Kirill A. Shutemov" To: Qian Cai Cc: Andrew Morton , elver@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, peterz@infradead.org, syzbot+c034966b0b02f94f7f34@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: Re: [PATCH -next] fork: annotate a data race in vm_area_dup() Message-ID: <20200218103002.6rtjreyqjepo3yxe@box> References: <20200217223138.doaph66iwprbwhw5@box> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Feb 17, 2020 at 10:59:47PM -0500, Qian Cai wrote: >=20 >=20 > > On Feb 17, 2020, at 5:31 PM, Kirill A. Shutemov wrote: > >=20 > > I'm confused. AFAICS both sides hold mmap_sem on write: > >=20 > > - vm_mmap_pgoff() takes mmap_sem for the write on the write side > >=20 > > - do_mprotect_pkey() takes mmap_sem for the write on the read side > >=20 > >=20 > > What do I miss? >=20 > Ah, good catch. I missed the locking for the read there. This is intere= sting because Marco > did confirmed that the concurrency could happen, >=20 > https://lore.kernel.org/lkml/20191025173511.181416-1-elver@google.com/ >=20 > If that means KCSAN is not at fault, then I could think of two things, >=20 > 1) someone downgrades the lock. >=20 > I don=E2=80=99t think that a case here. Only __do_munmap() will do that= but I did not see how > it will affect us here. >=20 > 2) the reader and writer are two different processes. >=20 > So, they held a different mmap_sem, but I can=E2=80=99t see how could t= wo processes shared > the same vm_area_struct. Also, file->f_mapping->i_mmap was also stored = in the > writer, but I can=E2=80=99t see how it was also loaded in the reader. >=20 > Any ideas? I think I've got this: vm_area_dup() blindly copies all fields of orignal VMA to the new one. This includes coping vm_area_struct::shared.rb which is normally protecte= d by i_mmap_lock. But this is fine because the read value will be overwritten on the following __vma_link_file() under proper protectection= . So the fix is correct, but justificaiton is lacking. Also, I would like to more fine-grained annotation: marking with data_race() 200 bytes copy may hide other issues. --=20 Kirill A. Shutemov