From patchwork Fri Sep 11 22:45:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 7164401 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 037F9BEEC1 for ; Fri, 11 Sep 2015 22:46:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1EEAF205E6 for ; Fri, 11 Sep 2015 22:46:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23D9D2062E for ; Fri, 11 Sep 2015 22:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754223AbbIKWqA (ORCPT ); Fri, 11 Sep 2015 18:46:00 -0400 Received: from mail.kernel.org ([198.145.29.136]:36750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753947AbbIKWp7 (ORCPT ); Fri, 11 Sep 2015 18:45:59 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C71742058C; Fri, 11 Sep 2015 22:45:52 +0000 (UTC) Received: from localhost (unknown [166.170.36.75]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DCF6820585; Fri, 11 Sep 2015 22:45:51 +0000 (UTC) Date: Fri, 11 Sep 2015 15:45:50 -0700 From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: stable@vger.kernel.org Subject: Re: [PATCH v2] f2fs crypto: allocate buffer for decrypting filename Message-ID: <20150911224550.GA73045@jaegeuk-mac02.mot.com> References: <1441936062-69511-1-git-send-email-jaegeuk@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1441936062-69511-1-git-send-email-jaegeuk@kernel.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change log from v1: o fix wrong pointer assignment From a0f3577cab882adc70d71e733d62c48aab61c3a4 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Thu, 3 Sep 2015 13:38:23 -0700 Subject: [PATCH] f2fs crypto: allocate buffer for decrypting filename We got dentry pages from high_mem, and its address space directly goes into the decryption path via f2fs_fname_disk_to_usr. But, sg_init_one assumes the address is not from high_mem, so we can get this panic since it doesn't call kmap_high but kunmap_high is triggered at the end. kernel BUG at ../../../../../../kernel/mm/highmem.c:290! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP ARM ... (kunmap_high+0xb0/0xb8) from [] (__kunmap_atomic+0xa0/0xa4) (__kunmap_atomic+0xa0/0xa4) from [] (blkcipher_walk_done+0x128/0x1ec) (blkcipher_walk_done+0x128/0x1ec) from [] (crypto_cbc_decrypt+0xc0/0x170) (crypto_cbc_decrypt+0xc0/0x170) from [] (crypto_cts_decrypt+0xc0/0x114) (crypto_cts_decrypt+0xc0/0x114) from [] (async_decrypt+0x40/0x48) (async_decrypt+0x40/0x48) from [] (f2fs_fname_disk_to_usr+0x124/0x304) (f2fs_fname_disk_to_usr+0x124/0x304) from [] (f2fs_fill_dentries+0xac/0x188) (f2fs_fill_dentries+0xac/0x188) from [] (f2fs_readdir+0x1f0/0x300) (f2fs_readdir+0x1f0/0x300) from [] (vfs_readdir+0x90/0xb4) (vfs_readdir+0x90/0xb4) from [] (SyS_getdents64+0x64/0xcc) (SyS_getdents64+0x64/0xcc) from [] (ret_fast_syscall+0x0/0x30) Cc: Signed-off-by: Jaegeuk Kim --- fs/f2fs/dir.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 8f15fc1..cce512c 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -773,6 +773,7 @@ bool f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, unsigned int bit_pos; struct f2fs_dir_entry *de = NULL; struct f2fs_str de_name = FSTR_INIT(NULL, 0); + char *name = NULL; bit_pos = ((unsigned long)ctx->pos % d->max); @@ -788,8 +789,10 @@ bool f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, d_type = DT_UNKNOWN; /* encrypted case */ - de_name.name = d->filename[bit_pos]; de_name.len = le16_to_cpu(de->name_len); + name = kmalloc(de_name.len, GFP_NOFS); + memcpy(name, d->filename[bit_pos], de_name.len); + de_name.name = name; if (f2fs_encrypted_inode(d->inode)) { int save_len = fstr->len; @@ -799,13 +802,18 @@ bool f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, &de_name, fstr); de_name = *fstr; fstr->len = save_len; - if (ret < 0) + if (ret < 0) { + kfree(name); return true; + } } if (!dir_emit(ctx, de_name.name, de_name.len, - le32_to_cpu(de->ino), d_type)) + le32_to_cpu(de->ino), d_type)) { + kfree(name); return true; + } + kfree(name); bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len)); ctx->pos = start_pos + bit_pos;