Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4038968imu; Sat, 24 Nov 2018 16:59:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/WGl292SuIA5SNcIzscTmY90tVVHbd3NnfoLnucygR+ZGs9136lz2ewKHHFPa0reBy4gkcD X-Received: by 2002:a17:902:59d6:: with SMTP id d22mr22144566plj.10.1543107586751; Sat, 24 Nov 2018 16:59:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543107586; cv=none; d=google.com; s=arc-20160816; b=TQQEFixlT/2vrKBOtXXMKk/lTe1ispUTvmgXRefNLymJB0c/D6DjfJKdpx4W/oP2pM PeaU897RMntIDJt/2GZzk53lC8gJzX9f5EQcf4M+AA/5UNPEkmGGfGzw35aNQXtBtZPL TpfPmmB53yYTR/ZylebtoR+8hWUutkIkrHSxl8MeKjD0BxT0DAXojEtZFR5jYdBlapyD 5Vu5pzUFR3Lnxf4YSQo3QIpkiYY0jJRi2MgmXsgEX8fmnm+R+Mjh/1ByDeiX9/RPXZoe fy7sn62TY8KdOUu39UL+lUAkvtuhc4T0/7VKcbEMEh8knTlpce96HY85WG4y9IWygdtF Iidw== 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 :dkim-signature; bh=m5M4DMmmfC8+Hxib1IvpkBcysAcYi1Haj5CF53szmUY=; b=FaUdLyT+yFWMauiVeXToGUPOuloXQfW85gbKeEqQ9PjzemVgQObLMK1/FPn5x0Pr72 EdVZ7+bNem+bagGVp6l5nLakPYqgl5cz2g7WFfoXWO1TV9ywe6HNW4h9JYcFanSHNhH1 GKEJV1U5GVk49PIBVJ75uejcpJCqlePWzziuGA+bLXGEQUGTIYKF79t2RPQYjHbzvvgw OggtNk+djCWOO3Nld8TLoMbVIoUXyOEBzGLhiFwco1kPislhU8lo78tQGBir4UKZ1cfs 6WFOJXt4OpCcrzJtnNgtqqUxEuEE+S88DAVXX9arDWMMDM++hmREFJE6dazatRxoq9Xg uqXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=M5Rr+4os; 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 y18si27309277plp.269.2018.11.24.16.59.15; Sat, 24 Nov 2018 16:59:46 -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=@163.com header.s=s110527 header.b=M5Rr+4os; 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 S1726722AbeKYLsA (ORCPT + 99 others); Sun, 25 Nov 2018 06:48:00 -0500 Received: from m12-16.163.com ([220.181.12.16]:54106 "EHLO m12-16.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726323AbeKYLsA (ORCPT ); Sun, 25 Nov 2018 06:48:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=m5M4DMmmfC8+Hxib1I vpkBcysAcYi1Haj5CF53szmUY=; b=M5Rr+4osRIjWtlEQUR6z3UnVr+uw33S4oH GKRmKWFTMTeRjkYbEABpLI0EQUxfSekRGbzGT0ogLkdOjNum2wmL1TFA7fXo/Grz XTAp78fowzZiDzJX8HaZ9q0c28TahwBvn976mTKSJhQRnDbs8+QgFo9hco+wbqlX Y0mD1hHPE= Received: from bp.localdomain (unknown [106.120.213.96]) by smtp12 (Coremail) with SMTP id EMCowADHV1ef8_lbtG7IBg--.31384S3; Sun, 25 Nov 2018 08:58:10 +0800 (CST) From: Pan Bian To: Jan Kara Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH] ext2: fix potential use after free Date: Sun, 25 Nov 2018 08:58:02 +0800 Message-Id: <1543107482-97334-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: EMCowADHV1ef8_lbtG7IBg--.31384S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrtFWkZFyDtrW8Cw1UuryxuFg_yoW3Xwb_Ka 4UJw4Ikrs5GrZYq3WxAFWYy3Z5Kas5Ar1rur4rGr13ZayUtFZ7ZFyDXrWfZr15Xw47Gan8 WF4kXry3ArWIgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU0ubyJUUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiVBoKclUMGJWYxQAAs- Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function ext2_xattr_set calls brelse(bh) to drop the reference count of bh. After that, bh may be freed. However, following brelse(bh), it reads bh->b_data via macro HDR(bh). This may result in a use-after-free bug. This patch moves brelse(bh) after reading field. Signed-off-by: Pan Bian --- fs/ext2/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c index 62d9a659a..dd8f10d 100644 --- a/fs/ext2/xattr.c +++ b/fs/ext2/xattr.c @@ -612,9 +612,9 @@ bad_block: ext2_error(sb, "ext2_xattr_set", } cleanup: - brelse(bh); if (!(bh && header == HDR(bh))) kfree(header); + brelse(bh); up_write(&EXT2_I(inode)->xattr_sem); return error; -- 2.7.4