Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5901468ybv; Tue, 18 Feb 2020 06:11:18 -0800 (PST) X-Google-Smtp-Source: APXvYqx/9Lb5yAMYtrIVlQYLL/ddLRHISCC2zZrUTLuYn+kOYC7HQwzbdisLRaes6pJUXHijd1UY X-Received: by 2002:aca:ebc3:: with SMTP id j186mr1279036oih.15.1582035078867; Tue, 18 Feb 2020 06:11:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582035078; cv=none; d=google.com; s=arc-20160816; b=mqA0o4Hq581ruTw5HEctRe4cj5CKk3Z53aqVblexSBGVtKVzlt6REy24sP5Z+17DYx ++Q3jsf1VyEwb1p/ZEJMy2s3rv87IuxfKcPSfEMEpsr3zZNtAA1sL/aSLv8T47RS4AZ0 TPUzj/nQI5RXZjT4G+iIIkJjI17+suWp0t4L/dMvP7ZApfj0xI2UC0VQwDA0CyzsbQPD w0uTvtjYOK6E/DYCG4VRcC19NcyN+Djcsy/QhuPpxK2jJb5/Wu+t7CgTgjHCBfCcIW0Q P10GqnFYKHEfj8gnKmri4xOpivdlgldNjU8zpeFbHlNj7iFAnSMPkmn165GKRX55kEua t+jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Y9w13/tfZTffVdCMe2kCDHSUE9opbbsLGQSUEHoko5U=; b=ShrPqAj9MAQCU6EQOxsPGjZ6am86msnDQP1xY+wvlG40Vw0qHW/YNW07hLa8vM3/gF My3WcEo3uOlhXyLSuqzwTQqVbEUvsWxUPn9a6l3elmxUfWjX29jR6Hbn4fgfEPzb/hks 1wi6ZwS8YlnK1BDnB+978+5Jj/aaZs6Fhr2iWXGrFMeMWi6lBl1YB+JogVTaxKngW9h6 zLo3HAiQJu45CfFjeorpuHYPSe8MIFjp7KuacKzldhC7gs3miGcr/4odbek7mRlTOPip iNTcWCSM0JEIWcAWSg7flRQAtZN0rQ38R5a9LrqHVS9gmWmM0HPFsEWAjeDp58iQ8tfY q4yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZnoNvW0J; 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 h139si7635326oib.85.2020.02.18.06.11.05; Tue, 18 Feb 2020 06:11:18 -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=@google.com header.s=20161025 header.b=ZnoNvW0J; 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 S1726655AbgBROJg (ORCPT + 99 others); Tue, 18 Feb 2020 09:09:36 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:39619 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbgBROJg (ORCPT ); Tue, 18 Feb 2020 09:09:36 -0500 Received: by mail-ot1-f68.google.com with SMTP id 77so19593288oty.6 for ; Tue, 18 Feb 2020 06:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Y9w13/tfZTffVdCMe2kCDHSUE9opbbsLGQSUEHoko5U=; b=ZnoNvW0JGNymhsudEZqj4eoZL6SliYBlFQN7OmbbDWtZ+DW/BAxE3hwh/GxzzOUq4I M14C03Y2T+WaaeCiZoUFUPZV9q4zgIZs8yBv8AnDW72hrDDM6y0NkeVo7zaJ40jqROow v8qPHUVDlCW+bds4jvDZv36VciX3KYf4LtCp5k4pcr8ly/3m77mKsJuXokfH7/UPJzfH nqTxQusEkwdKvIDkVZC81F8FbvGRU0IT2MTpGKQeUj5F2pk+dSN22zPstNJZzEVW1KAn JXjtLv6fd60NLxAXjxGyN9XhcueGuh4dWszfAnh55nBzaJl+pOp7AYmVDGNaANbVFIyL Aqjg== 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:content-transfer-encoding; bh=Y9w13/tfZTffVdCMe2kCDHSUE9opbbsLGQSUEHoko5U=; b=sXMRqQLA2Y2iMKK30KoQ8JfeS3N0c6pJa9ZqEUe96HFqzat6bg0fyk+ZWAXsrm3/24 ZrC0skcshefYEnpis+5FdEMeMnTOqfEJf1qfjf0BAXgM+R8m7k65ivw73ESIbbz2bWDi uM8SPM8o2frrjaUzWAvNcWZUyF9oyLVBCYMDErIuSN8uLS0+yBJsQBdbdOacebi7auVI ZYXcNl5CJvqgZKhW46Xsohb9Eidyx86r/Hrock1n+lQpX2TDliDvMfYB86q07aIxkK1J jrEGnlCSeSr2UYizWGxpP3nbqR3Szx54LWDV/rPxPOUvZk5Gc4HpGZgqSKbZQMFvgc3w VMJA== X-Gm-Message-State: APjAAAULccsoJ9Tubkqck6dQ0+64U+d5tNOuRo90OvCi480CGbV7m6Yt TcJqPDOd0GCInCDA2nV00kDfPw3hntF2nyy9VR9qzP+twgw= X-Received: by 2002:a9d:66d1:: with SMTP id t17mr16550705otm.233.1582034975091; Tue, 18 Feb 2020 06:09:35 -0800 (PST) MIME-Version: 1.0 References: <20200218103002.6rtjreyqjepo3yxe@box> <93E6B243-9A0F-410C-8EE4-9D57E28AF5AF@lca.pw> In-Reply-To: <93E6B243-9A0F-410C-8EE4-9D57E28AF5AF@lca.pw> From: Marco Elver Date: Tue, 18 Feb 2020 15:09:22 +0100 Message-ID: Subject: Re: [PATCH -next] fork: annotate a data race in vm_area_dup() To: Qian Cai Cc: "Kirill A. Shutemov" , Andrew Morton , Linux Memory Management List , LKML , Peter Zijlstra , syzbot , syzkaller-bugs Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 Feb 2020 at 13:40, Qian Cai wrote: > > > > > On Feb 18, 2020, at 5:29 AM, Kirill A. Shutemov = wrote: > > > > 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 protec= ted > > by i_mmap_lock. But this is fine because the read value will be > > overwritten on the following __vma_link_file() under proper protectecti= on. > > Right, multiple processes could share the same file-based address space w= here those vma have been linked into address_space::i_mmap via vm_area_stru= ct::shared.rb. Thus, the reader could see its shared.rb linkage pointers go= t updated by other processes. > > > > > 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. > > That is the harder part where I don=E2=80=99t think we have anything for = that today. Macro, any suggestions? ASSERT_IGNORE_FIELD()? There is no nice interface I can think of. All options will just cause more problems, inconsistencies, or annoyances. 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". 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? 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): 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); 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. 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_). Thanks, -- Marco