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.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 E230FC2D0EC for ; Fri, 10 Apr 2020 23:54:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7292C206DA for ; Fri, 10 Apr 2020 23:54:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VxFB2Kfi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7292C206DA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BB9D88E008A; Fri, 10 Apr 2020 19:54:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B43828E0067; Fri, 10 Apr 2020 19:54:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E43E8E008A; Fri, 10 Apr 2020 19:54:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0168.hostedemail.com [216.40.44.168]) by kanga.kvack.org (Postfix) with ESMTP id 8358D8E0067 for ; Fri, 10 Apr 2020 19:54:04 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3BCD5B78C for ; Fri, 10 Apr 2020 23:54:04 +0000 (UTC) X-FDA: 76693601208.19.land35_7acb94d291359 X-HE-Tag: land35_7acb94d291359 X-Filterd-Recvd-Size: 4987 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Fri, 10 Apr 2020 23:54:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586562843; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dKSzZGLxXpkpAxvp178c+wNakdjA+GflYeETpVU4+iQ=; b=VxFB2KfiwDYCapnNB8U9ORVAL5xjG9glmq02+MxPbnmrls8533jj4myEj+UVUnPycdOX/y LgmVHVnz7MJSq1F+o0RN1XODXbKpboO5VQps9LusfpEyxlN/4arzPxO80pry5uHDNBknuK InZrMTyWbAvOLy1yaV/y/fkCcz39Xb4= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-PjfnAuCWOIyZsEBV4vz2xA-1; Fri, 10 Apr 2020 19:54:01 -0400 X-MC-Unique: PjfnAuCWOIyZsEBV4vz2xA-1 Received: by mail-qv1-f72.google.com with SMTP id dr8so2933832qvb.5 for ; Fri, 10 Apr 2020 16:54:01 -0700 (PDT) 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:in-reply-to; bh=ksuILjkbg5TjsIuNKr3gPaLEdetOUxVmS2L3kl7C13w=; b=PklXPk57I/v9uHfEfJMNRvtvOEXj+3kQFuDcwHX8JpA1xGxZCDAsrv47KS7uxPjJzy DcDmuxLC9bBFpbPrpE9m9x4DXl/REdWTWuDFNDq9d13MLkJ0rq7Qihiqf0z46J1+W6rf ZmbBzgBJljTt/uGQdTAM9L+gnlc/5XV/iUdKI8t+tsCUNzTV+2KZl5iBnqqTe447EWpT gBBQMa//DLsHP9k21ZfGk5gspexLKljKflHkx+1m/x/SiSj8kqRJLuMXBGtTjQn8UXbw fB43ZQ5chIG8acHP3ZFAdV17CwdpANjz0gAX42QQGCrDuxKvCzODaxdXwbR9vjYNhY51 yXzw== X-Gm-Message-State: AGi0PuZLbETkJRZIMsYZw5IiB6bnUOXt/CVPKDGbqiqGjeIGYy8YYoua 36BQERpUm/PFc2n+y9YjEJ4ptwgv7vE9zcQ7kjqMX11HnkIleuqs7Q6tAuGNB4JCMPvoOApRRv+ aWO2Fhi6ZaXQ= X-Received: by 2002:a37:4015:: with SMTP id n21mr5900782qka.76.1586562840956; Fri, 10 Apr 2020 16:54:00 -0700 (PDT) X-Google-Smtp-Source: APiQypJesmPy4hb9MhKbqjA1zmQdSkavM3B+hDYuBFLqSwdbcxJi7L1HZ0g10Amy1w/QHqRFj6ivzg== X-Received: by 2002:a37:4015:: with SMTP id n21mr5900771qka.76.1586562840666; Fri, 10 Apr 2020 16:54:00 -0700 (PDT) Received: from xz-x1 ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id v77sm2760807qkb.24.2020.04.10.16.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Apr 2020 16:53:59 -0700 (PDT) Date: Fri, 10 Apr 2020 19:53:58 -0400 From: Peter Xu To: Linus Torvalds Cc: Andrew Morton , ira.weiny@intel.com, Linux-MM , miles.chen@mediatek.com, mm-commits@vger.kernel.org Subject: Re: [patch 07/35] mm/gup: fix null pointer dereference detected by coverity Message-ID: <20200410235358.GA38470@xz-x1> References: <20200410143047.bf34a933ce1affdc042c7c80@linux-foundation.org> <20200410213235.M6eTaELL2%akpm@linux-foundation.org> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Apr 10, 2020 at 03:24:37PM -0700, Linus Torvalds wrote: > On Fri, Apr 10, 2020 at 2:32 PM Andrew Morton = wrote: > > > > In fixup_user_fault(), it is possible that unlocked is NULL, > > so we should test unlocked before using it. >=20 > This seems wrong. >=20 > > For example, in arch/arc/kernel/process.c, NULL is passed > > to fixup_user_fault(). > > > > ret =3D fixup_user_fault(current, current->mm, (unsigned long) = uaddr, > > FAULT_FLAG_WRITE, NULL); >=20 > Yes, but it doesn't set FAULT_FLAG_ALLOW_RETRY, exactly _because_ > 'unlocked' is NULL. >=20 > Basically, retry is fundamentally tied to that "unlocked" flag. You > can't ask for retry without also saying "please tell me if you > unlocked the mmap_sem during the retry". So the two go hand in hand > there. >=20 > So I think this is just coverity not understanding the rules. Yeah that's also my understanding - VM_FAULT_RETRY should depend on FAULT_FLAG_ALLOW_RETRY, which further depends on unlocked !=3D NULL. Though I'm not sure how to teach Coverity about the fact. Maybe a "BUG_ON(unlocked =3D=3D NULL)" (which contains an unreachable() inside) before referencing unlocked? Thanks, >=20 > Or maybe I'm the one missing something. Did you actually see a problem? >=20 > Linus >=20 --=20 Peter Xu