Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1555893ybz; Thu, 23 Apr 2020 00:47:14 -0700 (PDT) X-Google-Smtp-Source: APiQypI2gx5P/+qMY38ZdpKx1ATWEpKCu6c8SbLxtR+xgOaNptBx1sroQd+1zftAlLI5bx8+QRm2 X-Received: by 2002:a17:906:4e46:: with SMTP id g6mr1603301ejw.36.1587628034219; Thu, 23 Apr 2020 00:47:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587628034; cv=none; d=google.com; s=arc-20160816; b=UbbEb2dsQRBnAIGx9VDZs3oEmD2ZMVS5BBbBnOy3BWE9Rhgztqhvz1AZt/hIS9dWCm qZ4WbRIUhpprlg3Ms9XOrBOGWQB3TlpELA+lyevWgKJr+kMb6Xl8sUuAGykASG6bS4Kp J+h65eChpqv8W72qPSTEAVCjo6s3kCEYGj2si9yXNuAHA0lN6U8g4rJcZwKZVnWOhGr/ mzAWU5kV7UF4y0W2UYy4ObnXMQLd7bWlFYRCMqZUrZNlqfyTIPmdQABo3dvlFo5NGMfC PgKOJOXTGLbvScE/0Ht6mNvS4MRc/bcmYFQDn0uHh8PD0Yo2ExefhbsLx6GWP6w4A6Cn nUYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=Rk+EVRa80pcaGjMqd5eFMe2TwB80Xu57FP3iPQcm2m0=; b=gaTjM9lsrgB57ugyrukDjzkVDogHY1YTqDV4ruJwajh3NQdYktHxZtSveyj8yUVHvQ tygLQOSnyzsnPyeF6EB6NgEhtGaiaS9xc6O76sKYE6uQg733jY1B5NAx4tsobe+bUz5q IaZ8FgLBmAtv+6nEeoBuKE79mZf5qM8v1Uxxg5e0aK/7eAQBUHwjB8DA4NnWkJ6BTBtL EKggrRP1sFSadVaFXxrp10LgsH9+TUCGskXPIf5OQwgLJaYb3qR3shhwvtQ2Vi/vwQiE eUhB3g+uqUwQAXwcH+qusY4sqmOqBEByge+AFu4ZZpXZQzc+b96hE3O0DoBxt80GsLxk kpGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si793048ejr.449.2020.04.23.00.46.49; Thu, 23 Apr 2020 00:47:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726933AbgDWHqq (ORCPT + 99 others); Thu, 23 Apr 2020 03:46:46 -0400 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:41625 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726692AbgDWHqp (ORCPT ); Thu, 23 Apr 2020 03:46:45 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01355;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0TwPIgRU_1587628004; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0TwPIgRU_1587628004) by smtp.aliyun-inc.com(127.0.0.1); Thu, 23 Apr 2020 15:46:44 +0800 From: Jeffle Xu To: tytso@mit.edu, jack@suse.cz Cc: linux-ext4@vger.kernel.org, joseph.qi@linux.alibaba.com Subject: [PATCH v2] ext4: fix error pointer dereference Date: Thu, 23 Apr 2020 15:46:44 +0800 Message-Id: <1587628004-95123-1-git-send-email-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Don't pass error pointers to brelse(). commit 7159a986b420 ("ext4: fix some error pointer dereferences") has fixed some cases, fix the remaining one case. Once ext4_xattr_block_find()->ext4_sb_bread() failed, error pointer is stored in @bs->bh, which will be passed to brelse() in the cleanup routine of ext4_xattr_set_handle(). This will then cause a NULL panic crash in __brelse(). BUG: unable to handle kernel NULL pointer dereference at 000000000000005b RIP: 0010:__brelse+0x1b/0x50 Call Trace: ext4_xattr_set_handle+0x163/0x5d0 ext4_xattr_set+0x95/0x110 __vfs_setxattr+0x6b/0x80 __vfs_setxattr_noperm+0x68/0x1b0 vfs_setxattr+0xa0/0xb0 setxattr+0x12c/0x1a0 path_setxattr+0x8d/0xc0 __x64_sys_setxattr+0x27/0x30 do_syscall_64+0x60/0x250 entry_SYSCALL_64_after_hwframe+0x49/0xbe In this case, @bs->bh stores '-EIO' actually. Fixes: fb265c9cb49e ("ext4: add ext4_sb_bread() to disambiguate ENOMEM cases") Signed-off-by: Jeffle Xu Reviewed-by: Joseph Qi Cc: stable@kernel.org # 2.6.19 --- fs/ext4/xattr.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c index 21df43a..01ba663 100644 --- a/fs/ext4/xattr.c +++ b/fs/ext4/xattr.c @@ -1800,8 +1800,11 @@ struct ext4_xattr_block_find { if (EXT4_I(inode)->i_file_acl) { /* The inode already has an extended attribute block. */ bs->bh = ext4_sb_bread(sb, EXT4_I(inode)->i_file_acl, REQ_PRIO); - if (IS_ERR(bs->bh)) - return PTR_ERR(bs->bh); + if (IS_ERR(bs->bh)) { + error = PTR_ERR(bs->bh); + bs->bh = NULL; + return error; + } ea_bdebug(bs->bh, "b_count=%d, refcount=%d", atomic_read(&(bs->bh->b_count)), le32_to_cpu(BHDR(bs->bh)->h_refcount)); -- 1.8.3.1