From patchwork Thu May 17 17:43:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10407413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CEB8060155 for ; Thu, 17 May 2018 17:43:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFFFF2860A for ; Thu, 17 May 2018 17:43:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3FEC28647; Thu, 17 May 2018 17:43:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6718E2860A for ; Thu, 17 May 2018 17:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751907AbeEQRnj (ORCPT ); Thu, 17 May 2018 13:43:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:47390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751233AbeEQRnj (ORCPT ); Thu, 17 May 2018 13:43:39 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1C19F204EE; Thu, 17 May 2018 17:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526579018; bh=w0MwqmJqs4MRpzPaxmnY45Yf6BCwA47U4LGYhsYRHu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uHwwpWnnd1B9atH28GtBjBbYXHr5lNMB46OqU/Io2E5ERRjM96GuKafTsO8kaf/RN B+GoNVM6H6fG7xYR22qnCDysGRmWGm8W4UvnmmwO+BES937CXSvr/Liei/2kCzjb5u P+oD3MbowbP+x89rvg2KgMZbHesMz6E6t6thXuOA= From: Jeff Layton To: viro@zeniv.linux.org.uk Cc: jack@suse.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, lurodriguez@suse.de Subject: [PATCH v2] vfs: avoid dereferencing pointers in iterate_supers callbacks Date: Thu, 17 May 2018 13:43:36 -0400 Message-Id: <20180517174336.18529-1-jlayton@kernel.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180517154646.18751-1-jlayton@kernel.org> References: <20180517154646.18751-1-jlayton@kernel.org> 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 From: Jeff Layton All of the callback functions for iterate_supers either ignore the opaque argument, or dereference the pointer only to fetch the int to which it points. Change quota_sync_one to just cast the int from the pointer, and change sync_fs_one_sb to just use a NULL/non-NULL pointer as a flag. Signed-off-by: Jeff Layton --- fs/quota/quota.c | 4 ++-- fs/sync.c | 20 +++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/fs/quota/quota.c b/fs/quota/quota.c index 860bfbe7a07a..8dc76d5f87c7 100644 --- a/fs/quota/quota.c +++ b/fs/quota/quota.c @@ -48,7 +48,7 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd, static void quota_sync_one(struct super_block *sb, void *arg) { - int type = *(int *)arg; + int type = (unsigned long)arg; if (sb->s_qcop && sb->s_qcop->quota_sync && (sb->s_quota_types & (1 << type))) @@ -63,7 +63,7 @@ static int quota_sync_all(int type) return -EINVAL; ret = security_quotactl(Q_SYNC, type, 0, NULL); if (!ret) - iterate_supers(quota_sync_one, &type); + iterate_supers(quota_sync_one, (void *)((unsigned long)type)); return ret; } diff --git a/fs/sync.c b/fs/sync.c index b54e0541ad89..d7330bb97f05 100644 --- a/fs/sync.c +++ b/fs/sync.c @@ -76,8 +76,10 @@ static void sync_inodes_one_sb(struct super_block *sb, void *arg) static void sync_fs_one_sb(struct super_block *sb, void *arg) { + int wait = arg ? 1 : 0; + if (!sb_rdonly(sb) && sb->s_op->sync_fs) - sb->s_op->sync_fs(sb, *(int *)arg); + sb->s_op->sync_fs(sb, wait); } static void fdatawrite_one_bdev(struct block_device *bdev, void *arg) @@ -107,12 +109,10 @@ static void fdatawait_one_bdev(struct block_device *bdev, void *arg) */ void ksys_sync(void) { - int nowait = 0, wait = 1; - wakeup_flusher_threads(WB_REASON_SYNC); iterate_supers(sync_inodes_one_sb, NULL); - iterate_supers(sync_fs_one_sb, &nowait); - iterate_supers(sync_fs_one_sb, &wait); + iterate_supers(sync_fs_one_sb, NULL); + iterate_supers(sync_fs_one_sb, (void *)1UL); iterate_bdevs(fdatawrite_one_bdev, NULL); iterate_bdevs(fdatawait_one_bdev, NULL); if (unlikely(laptop_mode)) @@ -127,17 +127,15 @@ SYSCALL_DEFINE0(sync) static void do_sync_work(struct work_struct *work) { - int nowait = 0; - /* * Sync twice to reduce the possibility we skipped some inodes / pages * because they were temporarily locked */ - iterate_supers(sync_inodes_one_sb, &nowait); - iterate_supers(sync_fs_one_sb, &nowait); + iterate_supers(sync_inodes_one_sb, NULL); + iterate_supers(sync_fs_one_sb, NULL); iterate_bdevs(fdatawrite_one_bdev, NULL); - iterate_supers(sync_inodes_one_sb, &nowait); - iterate_supers(sync_fs_one_sb, &nowait); + iterate_supers(sync_inodes_one_sb, NULL); + iterate_supers(sync_fs_one_sb, NULL); iterate_bdevs(fdatawrite_one_bdev, NULL); printk("Emergency Sync complete\n"); kfree(work);