From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754207AbdBVFjl (ORCPT ); Wed, 22 Feb 2017 00:39:41 -0500 Received: from LGEAMRELO12.lge.com ([156.147.23.52]:36149 "EHLO lgeamrelo12.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750878AbdBVFje (ORCPT ); Wed, 22 Feb 2017 00:39:34 -0500 X-Original-SENDERIP: 156.147.1.127 X-Original-MAILFROM: minchan@kernel.org X-Original-SENDERIP: 10.177.223.161 X-Original-MAILFROM: minchan@kernel.org From: Minchan Kim To: Andrew Morton Cc: linux-kernel@vger.kernel.org, kernel-team@lge.com, Minchan Kim , Matthew Wilcox , stable@vger.kernel.org Subject: [PATCH] mm: do not access page->mapping directly on page_endio Date: Wed, 22 Feb 2017 14:39:24 +0900 Message-Id: <1487741964-17913-1-git-send-email-minchan@kernel.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With rw_page, page_endio is used for completing IO on a page and it propagates write error to the address space if the IO fails. The problem is it accesses page->mapping directly which might be okay for file-backed pages but it shouldn't for anonymous page. Otherwise, it can corrupt one of field from anon_vma under us and system goes panic randomly. Cc: Matthew Wilcox Cc: Signed-off-by: Minchan Kim --- mm/filemap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 2ba46f410c7c..1944c631e3e6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1008,9 +1008,12 @@ void page_endio(struct page *page, bool is_write, int err) unlock_page(page); } else { if (err) { + struct address_space *mapping; + SetPageError(page); - if (page->mapping) - mapping_set_error(page->mapping, err); + mapping = page_mapping(page); + if (mapping) + mapping_set_error(mapping, err); } end_page_writeback(page); } -- 2.7.4