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=-2.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_2 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 DE713C34026 for ; Tue, 18 Feb 2020 15:00:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7FE4524649 for ; Tue, 18 Feb 2020 15:00:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=lca.pw header.i=@lca.pw header.b="eSZVmwVa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7FE4524649 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lca.pw Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 26B036B0003; Tue, 18 Feb 2020 10:00:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 21A496B0006; Tue, 18 Feb 2020 10:00:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E4276B0007; Tue, 18 Feb 2020 10:00:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id EA84A6B0003 for ; Tue, 18 Feb 2020 10:00:40 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7F99F4DB3 for ; Tue, 18 Feb 2020 15:00:40 +0000 (UTC) X-FDA: 76503559440.16.star23_5bf3e477cd2d X-HE-Tag: star23_5bf3e477cd2d X-Filterd-Recvd-Size: 6516 Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 18 Feb 2020 15:00:39 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id v25so14679389qto.7 for ; Tue, 18 Feb 2020 07:00:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=o9sBoUPUqO81jEFCnxVttX8yCrxeL2usN9PLh+pjJ3o=; b=eSZVmwVa2gbbGMwMBbKARsAd7cwBPFl00qDx0B2YhBIRPvtxboPzJsFssHP2a80lsc 4vF/4Mk9CH7lpPDGv7jvgX3kUE0C8cx9L+m0vGGhyHp+V1Xwnq762gh5SAbSdWw4PDn4 ITxMO+y/SNAHSwbRai4jALTtbnLMhgttn4nqOnDpka8DEASRlBUsgGJB/FShle4gOMbB R+qW+74WmicKGgvlCp0d/VFjDZz3wMgruiBadc3GeHICdlRdxb/N1wRi8jnVNTr5gtpm MT3elb7KwBbU3dhcvRcDc18mrTvfGLn0X2IIEwyG3RbsWjb5BLybomWjfg01nPLuZovV ciGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=o9sBoUPUqO81jEFCnxVttX8yCrxeL2usN9PLh+pjJ3o=; b=SsfN2i/opLbGJFUrcLCHO5Cnjt03UXGIAaeOXsSI0bAZIwiuGBn0rFtOUtox6ribox W2lUpwdSnI/4lDOsFG1T4f2mbqFSWy0IPePHOtSHxjzkdHR1WVOFEEjAXxdLfzVL+1BC wazqWANqKELg2YihlKRhJbQkLdGFdRaEPk7G846N/9R9a1hGc4uRjZw4ihlyRVlehBjB dUYsDEXbT9Luok5AM0Z9xlS3HeoVxN/Ri6/7Aaeup63b7Q2c0+EWC5MFyhGAE1d12HV1 hT0yyprlrePkheMU+XG5HROtZhcbPDYy+I5lFZoIWP0BoICzIdpHlYsDUI5yra6FoLI/ PDqA== X-Gm-Message-State: APjAAAXbr99HVUT9z+337dGBAxD5l4H2oIdJVlzXXvL3vBVIVCKWmL5q 4hmxxB8VBW15vYJ9RhN7Y2SATw== X-Google-Smtp-Source: APXvYqylsE1qbtN1Q//rOh0WFFDimHe+/9iLy/BtPX+LViPUw+eMK+jjmTxcqviyH1QdlQADIyb8sQ== X-Received: by 2002:ac8:6bc1:: with SMTP id b1mr17126390qtt.313.1582038037225; Tue, 18 Feb 2020 07:00:37 -0800 (PST) Received: from dhcp-41-57.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id q6sm1950780qkm.46.2020.02.18.07.00.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Feb 2020 07:00:36 -0800 (PST) Message-ID: <1582038035.7365.93.camel@lca.pw> Subject: Re: [PATCH -next] fork: annotate a data race in vm_area_dup() From: Qian Cai To: Marco Elver Cc: "Kirill A. Shutemov" , Andrew Morton , Linux Memory Management List , LKML , Peter Zijlstra , syzbot , syzkaller-bugs Date: Tue, 18 Feb 2020 10:00:35 -0500 In-Reply-To: References: <20200218103002.6rtjreyqjepo3yxe@box> <93E6B243-9A0F-410C-8EE4-9D57E28AF5AF@lca.pw> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6 (3.22.6-10.el7) Mime-Version: 1.0 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 Tue, 2020-02-18 at 15:09 +0100, Marco Elver wrote: > On Tue, 18 Feb 2020 at 13:40, Qian Cai wrote: > >=20 > >=20 > >=20 > > > On Feb 18, 2020, at 5:29 AM, Kirill A. Shutemov wrote: > > >=20 > > > I think I've got this: > > >=20 > > > vm_area_dup() blindly copies all fields of orignal VMA to the new o= ne. > > > This includes coping vm_area_struct::shared.rb which is normally pr= otected > > > by i_mmap_lock. But this is fine because the read value will be > > > overwritten on the following __vma_link_file() under proper protect= ection. > >=20 > > Right, multiple processes could share the same file-based address spa= ce where those vma have been linked into address_space::i_mmap via vm_are= a_struct::shared.rb. Thus, the reader could see its shared.rb linkage poi= nters got updated by other processes. > >=20 > > >=20 > > > So the fix is correct, but justificaiton is lacking. > > >=20 > > > Also, I would like to more fine-grained annotation: marking with > > > data_race() 200 bytes copy may hide other issues. > >=20 > > That is the harder part where I don=E2=80=99t think we have anything = for that today. Macro, any suggestions? ASSERT_IGNORE_FIELD()? >=20 > There is no nice interface I can think of. All options will just cause > more problems, inconsistencies, or annoyances. >=20 > Ideally, to not introduce more types of macros and keep it consistent, > ASSERT_EXCLUSIVE_FIELDS_EXCEPT(var, ...) maybe what you're after: > "Check no concurrent writers to struct, except ignore the provided > fields". >=20 > This option doesn't quite work, unless you just restrict it to 1 field > (we can't use ranges, because e.g. vm_area_struct has > __randomize_layout). The next time around, you'll want 2 fields, and > it won't work. Also, do we know that 'shared.rb' is the only thing we > want to ignore? >=20 > If you wanted something similar to ASSERT_EXCLUSIVE_BITS, it'd have to > be ASSERT_EXCLUSIVE_FIELDS(var, ...), however, this is quite annoying > for structs with many fields as you'd have to list all of them. It's > similar to what you can already do currently (but I also don't > recommend because it's unmaintainable): >=20 > ASSERT_EXCLUSIVE_WRITER(orig->vm_start); > ASSERT_EXCLUSIVE_WRITER(orig->vm_end); > ASSERT_EXCLUSIVE_WRITER(orig->vm_next); > ASSERT_EXCLUSIVE_WRITER(orig->vm_prev); > ... and so on ... > *new =3D data_race(*orig); >=20 > Also note that vm_area_struct has __randomize_layout, which makes > using ranges impossible. All in all, I don't see a terribly nice > option. >=20 > If, however, you knew that there are 1 or 2 fields only that you want > to make sure are not modified concurrently, ASSERT_EXCLUSIVE_WRITER + > data_race() would probably work well (or even ASSERT_EXCLUSIVE_ACCESS > if you want to make sure there are no writers nor _readers_). I am testing an idea that just do, lockdep_assert_held_write(&orig->vm_mm->mmap_sem); *new =3D data_race(*orig); The idea is that as long as we have the exclusive mmap_sem held in all pa= ths (auditing indicated so), no writer should be able to mess up our vm_area_= struct except the "shared.rb" field which has no harm.