Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5822436ybg; Tue, 22 Oct 2019 08:52:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7cJqqTioh6feiUxYreye0JNAmVohzLol78zkLBWY53kwSTBQiLFGb6O8z0+4uXOC8FRq0 X-Received: by 2002:a17:906:55d1:: with SMTP id z17mr28071999ejp.300.1571759556819; Tue, 22 Oct 2019 08:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571759556; cv=none; d=google.com; s=arc-20160816; b=s+l7X/YwCsgv/1A8U6mxJ/YC/I1m+b7h+F+WecOo9PembOD7TDP4L0SapvO2Ar97oG NUDtv5I/cqLhV6jnMmTBlPwgAFfQNIf6HT1d47rjvBk92RKxoU6kTI2ABonbOkK+47T8 iKvbtXoacukXsS+8FTabNz0LC+nbixckwswSWTPbU8xrnyAs4LyDuC1iaXUiV6gPDLSS GU4MBnjgFvJA+DDli6W1cTTs02gdNjT3240PUDl9kCUJbD4S50hoOl7VsxoNfCwYxLXB zv+tP4uEOPjtd8DslXPN3sAIE2+dmHUqM3VpHVZ8phs3mtsZ7uduziNOn8VHe5tmuDx7 M5WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject; bh=WIM3p8ubo9Nk5RIUX0bx9kVngz3FlhI4q0WEUXArZQM=; b=C143pW9bZVEfqCo4oksyR1I+xl+/p6Pd1Q5drqwNmBggqVUJ1J+fexFoApD37+9MCu RZKfaoXR03OxvdenjRfJHD827ilo4uyBq2+sXXJAB5GvfJA08rz+OV0hvRGEvVjBulYF 8IE0nebwm7+6ozsBFl3A0QOTX1KJvdXo5WsAu/eZkAQUFIGxC2431QDSiPoeC1jwHceI HfsztUpK/mXewT1iwRDzrxapj5rmb0dmZBK9x4bQRUerPdfHZJC2rryMU/1oOpQlQ7Ku pRILqp6iynwIihj+T7Xs7znofQ1XjpQ9e1TLxdY9GT2I76/RwAf8TAsK7bcH0TvkRQBT pb+Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k1si4916007eji.76.2019.10.22.08.52.12; Tue, 22 Oct 2019 08:52:36 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388719AbfJVNjG (ORCPT + 99 others); Tue, 22 Oct 2019 09:39:06 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:26814 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388581AbfJVNjG (ORCPT ); Tue, 22 Oct 2019 09:39:06 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x9MDcmEL125781 for ; Tue, 22 Oct 2019 09:39:05 -0400 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2vt1fnm28q-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 22 Oct 2019 09:39:04 -0400 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 22 Oct 2019 14:39:01 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 22 Oct 2019 14:38:57 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x9MDcvXt50069544 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 22 Oct 2019 13:38:57 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 595AC5205F; Tue, 22 Oct 2019 13:38:57 +0000 (GMT) Received: from [9.199.159.6] (unknown [9.199.159.6]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id B1B4752050; Tue, 22 Oct 2019 13:38:55 +0000 (GMT) Subject: Re: [PATCH RESEND 1/1] vfs: Really check for inode ptr in lookup_fast To: Al Viro , linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, wugyuan@cn.ibm.com, jlayton@kernel.org, hsiangkao@aol.com, Jan Kara References: <20190927044243.18856-1-riteshh@linux.ibm.com> <20191015040730.6A84742047@d06av24.portsmouth.uk.ibm.com> From: Ritesh Harjani Date: Tue, 22 Oct 2019 19:08:54 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20191015040730.6A84742047@d06av24.portsmouth.uk.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19102213-4275-0000-0000-000003759081 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19102213-4276-0000-0000-00003888B47D Message-Id: <20191022133855.B1B4752050@d06av21.portsmouth.uk.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-22_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1910220127 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I think we have still not taken this patch. Al? On 10/15/19 9:37 AM, Ritesh Harjani wrote: > ping!! > > On 9/27/19 10:12 AM, Ritesh Harjani wrote: >> d_is_negative can race with d_instantiate_new() >> -> __d_set_inode_and_type(). >> For e.g. in use cases where Thread-1 is creating >> symlink (doing d_instantiate_new()) & Thread-2 is doing >> cat of that symlink while doing lookup_fast (via REF-walk- >> one such case is, when ->permission returns -ECHILD). >> >> During this race if __d_set_and_inode_type() does out-of-order >> execution and set the dentry->d_flags before setting >> dentry->inode, then it can result into following kernel panic. >> >> This change fixes the issue by directly checking for inode. >> >> E.g. kernel panic, since inode was NULL. >> trailing_symlink() -> may_follow_link() -> inode->i_uid. >> Issue signature:- >>    [NIP  : trailing_symlink+80] >>    [LR   : trailing_symlink+1092] >>    #4 [c00000198069bb70] trailing_symlink at c0000000004bae60 >> (unreliable) >>    #5 [c00000198069bc00] path_openat at c0000000004bdd14 >>    #6 [c00000198069bc90] do_filp_open at c0000000004c0274 >>    #7 [c00000198069bdb0] do_sys_open at c00000000049b248 >>    #8 [c00000198069be30] system_call at c00000000000b388 >> >> Sequence of events:- >> Thread-2(Comm: ln)            Thread-1(Comm: cat) >> >>                     dentry = __d_lookup() //nonRCU >> >> __d_set_and_inode_type() (Out-of-order execution) >>      flags = READ_ONCE(dentry->d_flags); >>      flags &= ~(DCACHE_ENTRY_TYPE | DCACHE_FALLTHRU); >>      flags |= type_flags; >>      WRITE_ONCE(dentry->d_flags, flags); >> >>                     if (unlikely(d_is_negative()) // fails >>                            {} >>                     // since d_flags is already updated in >>                     // Thread-2 in parallel but inode >>                     // not yet set. >>                     // d_is_negative returns false >> >>                     *inode = d_backing_inode(path->dentry); >>                     // means inode is still NULL >> >>      dentry->d_inode = inode; >> >>                     trailing_symlink() >>                         may_follow_link() >>                             inode = nd->link_inode; >>                             // nd->link_inode = NULL >>                             //Then it crashes while >>                             //doing inode->i_uid >> >> Reported-by: Guang Yuan Wu >> Tested-by: Guang Yuan Wu >> Acked-by: Jeff Layton >> Signed-off-by: Ritesh Harjani >> --- >>   fs/namei.c | 16 +++++++++++++++- >>   1 file changed, 15 insertions(+), 1 deletion(-) >> >> diff --git a/fs/namei.c b/fs/namei.c >> index 671c3c1a3425..7c5337cddebd 100644 >> --- a/fs/namei.c >> +++ b/fs/namei.c >> @@ -1617,7 +1617,21 @@ static int lookup_fast(struct nameidata *nd, >>           dput(dentry); >>           return status; >>       } >> -    if (unlikely(d_is_negative(dentry))) { >> + >> +    /* >> +     * Caution: d_is_negative() can race with >> +     * __d_set_inode_and_type(). >> +     * For e.g. in use cases where Thread-1 is creating >> +     * symlink (doing d_instantiate_new()) & Thread-2 is doing >> +     * cat of that symlink and falling here (via Ref-walk) while >> +     * doing lookup_fast (one such case is when ->permission >> +     * returns -ECHILD). >> +     * Now if __d_set_inode_and_type() does out-of-order execution >> +     * i.e. it first sets the dentry->d_flags & then dentry->inode >> +     * then it can result into inode being NULL, causing panic later. >> +     * Hence directly check if inode is NULL here. >> +     */ >> +    if (unlikely(d_really_is_negative(dentry))) { >>           dput(dentry); >>           return -ENOENT; >>       } >> >