Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp619901imm; Wed, 6 Jun 2018 03:19:33 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIY/hbaLuGCoSnSKvVu9JW3tCv5U8g6vtTvH9u0ve99tqksXsVOPnJGsIZMKZGEC+AMVVCu X-Received: by 2002:a17:902:b416:: with SMTP id x22-v6mr2621430plr.267.1528280373350; Wed, 06 Jun 2018 03:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528280373; cv=none; d=google.com; s=arc-20160816; b=ynSwGTsN+UfW1xy08DWi/YPeEkR1GiNwPVF0kATunnugOWh9sEMWudY0BgxyV7LDDa fU5oAXFBFwJTwzSwp8rVNR8wGGSeSL4Gm5LiNRNFE5KavzuHwCFAM0g0iGbO0edimFOJ qQTtPfe70ITOY6e0D6lELAzQU0ZMmgPIuCfw3hxW07wsbmlOrYiAaz/jFPSrnI5lEEln Y8a2orU/LfZcRFBptH6pWhDYHSWWZRFScKXwf7RLVXkuaVgOn2onJPweHUdskhXlE18R AKKud/P0lFKyNasVmKEouOuqPtLDqyekDfnNLVT96KV7vTFJxFbyMtKoFnQ6e39m206S ss/g== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=qz5I0NQx5RVc/Q9OGovxIoF+RFiEHcBjkhGR0oQCIbs=; b=A41P8/0/zKDi2P07Q0a2OSjQxuzYfSYE+lHHwHC8OXVsdJFuBONGLV/Fu38s9PFEA/ hIiQd2U2GSRfX/UcXe0VRV0ctHQEuHfa7xSBblrKfuY03c2v75DZT3mSr+7aLoZO3MqM /+bcUilgQBQjW3ZWyddp1+jjZhroR+CBJ6BeEJeiStBvCmvuDwPLEU3EFsAxGEknETyC 9I+6enu8kkQNz2PuYtk7B1mCd0NFwIRbymvk+1Zwkmz3IA6zOk4nUB2SWHJEc35CMETO e0X3+S5cwiWHl7SEg89eELgWhx/C5moVdXATwmebiXtL9RbrqPit96Zh2LUm/CAoooUc K6DQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f21-v6si23454451pfh.33.2018.06.06.03.19.19; Wed, 06 Jun 2018 03:19:33 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752415AbeFFKSJ (ORCPT + 99 others); Wed, 6 Jun 2018 06:18:09 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:64299 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752073AbeFFKSH (ORCPT ); Wed, 6 Jun 2018 06:18:07 -0400 Received: from fsav105.sakura.ne.jp (fsav105.sakura.ne.jp [27.133.134.232]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w56AHwjt052391; Wed, 6 Jun 2018 19:17:58 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav105.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp); Wed, 06 Jun 2018 19:17:58 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp) Received: from [192.168.1.8] (softbank126074194044.bbtec.net [126.74.194.44]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id w56AHquH052363 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 6 Jun 2018 19:17:58 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Subject: Re: general protection fault in sockfs_setattr To: shankarapailoor , Cong Wang Cc: David Miller , LKML , syzkaller , Linux Kernel Network Developers References: From: Tetsuo Handa Message-ID: <23d3edb6-a9cd-0295-5433-1b2a13ecbf21@I-love.SAKURA.ne.jp> Date: Wed, 6 Jun 2018 19:17:49 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pastebin says that it was 4.17.0-rc4+ rather than 4.17-rc7. I suggest reporting to Al Viro and linux-fsdevel ML after confirming that this bug still happens with linux.git , in case this is a dentry related bug (e.g. someone is by error calling dput() without getting a refcount). Also, please don't eliminate kernel messages prior to the crash. Sometimes previous kernel messages (e.g. memory allocation fault injection) as-is indicate the cause. On 2018/06/06 11:19, shankarapailoor wrote: > Hi Cong, > > I added that check and it seems to stop the crash. Like you said, I > don't see where the reference count for the file is increased. The > inode lock also seems to be held during this call. > > Regards, > Shankara > > > > On Tue, Jun 5, 2018 at 12:14 PM, Cong Wang wrote: >> On Mon, Jun 4, 2018 at 9:53 PM, shankarapailoor >> wrote: >>> Hi, >>> >>> I have been fuzzing Linux 4.17-rc7 with Syzkaller and found the >>> following crash: https://pastebin.com/ixX3RB9j >>> >>> Syzkaller isolated the cause of the bug to the following program: >>> >>> socketpair$unix(0x1, 0x1, 0x0, >>> &(0x7f0000000000)={0xffffffffffffffff, 0xffffffffffffffff}) >>> getresuid(&(0x7f0000000080)=0x0, &(0x7f00000000c0), >>> &(0x7f0000000700))r3 = getegid() >>> fchownat(r0, &(0x7f0000000040)='\x00', r2, r3, 0x1000) >>> dup3(r1, r0, 0x80000) >>> >>> >>> The problematic area appears to be here: >>> >>> static int sockfs_setattr(struct dentry *dentry, struct iattr *iattr) >>> { >>> int err = simple_setattr(dentry, iattr); >>> >>> if (!err && (iattr->ia_valid & ATTR_UID)) { >>> struct socket *sock = SOCKET_I(d_inode(dentry)); >>> >>> sock->sk->sk_uid = iattr->ia_uid; //KASAN GPF >>> } >>> return err; >>> } >>> >>> If dup3 is called concurrently with fchownat then can sock->sk be NULL? >> >> Although dup3() implies a close(), fd is refcnt'ted, if dup3() runs >> concurrently with fchownat() it should not be closed until whoever >> the last closes it. >> >> Or maybe fchownat() doesn't even hold refcnt of fd, since it aims >> to change the file backed. >> >> >> Not sure if the following is sufficient, inode might need to be protected >> with some lock... >> >> diff --git a/net/socket.c b/net/socket.c >> index f10f1d947c78..6294b4b3132e 100644 >> --- a/net/socket.c >> +++ b/net/socket.c >> @@ -537,7 +537,10 @@ static int sockfs_setattr(struct dentry *dentry, >> struct iattr *iattr) >> if (!err && (iattr->ia_valid & ATTR_UID)) { >> struct socket *sock = SOCKET_I(d_inode(dentry)); >> >> - sock->sk->sk_uid = iattr->ia_uid; >> + if (sock->sk) >> + sock->sk->sk_uid = iattr->ia_uid; >> + else >> + err = -ENOENT; >> } >> >> return err; > > >