Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2179952ybt; Fri, 3 Jul 2020 02:55:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfJuWbOyhQ8JdJiGenxhEybtGLPxXCdYwd+BK/hj7Pc0M3MWqtnlvbr81TG9247xIo4A+l X-Received: by 2002:a17:906:fb99:: with SMTP id lr25mr31389781ejb.49.1593770133406; Fri, 03 Jul 2020 02:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593770133; cv=none; d=google.com; s=arc-20160816; b=zigWzn2hDLbYqEf3bTYChqY/rnAlIdez9r+YkVvxYRPfEJEFF7Wt47LFV46IMIhBQe yvET+d4zLRpxwKAGqt+GZGdgJvDP8RTWfQOFn0CogfnoNUphtUwr/UQmYVIX+yPbjn3x qJ5eOpAs8QckvE0yy6y3gi1C8hTaROiE+oc647S5UcZ/RMeq+75NRNpvw0LD50NH10tY uCdqrP7RlBX5KzOJfOd7X9LqHKAUd1sMMYTLnz+jQzTdEEVqxsaGywmN254yVA6oWjr0 ojz7K8dbCcEtjaaLsNe5ZWSaJY78pq6YXVZYzJjUY837Ey0ZN2QC+/YvbYVxKoMkHzXd z4uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=bkk2qFfKQw7FQkZvEcDpG85NTJt8VpjE++sbyv9w5T8=; b=S+EsKHsmjjGX0e7oCEP1Xh+K++JjRZie/G4DliFh9HXYl1sUI88SVPOCvm4UMnKc28 XFmmdlw70hQd8AxBfhUlHtOwf+OA2hkBR7OxjU3wo5JnTUHImrYXBbnFaZZbA+n94Tpb u5E9fhliKg+elX4dF4lTAkrW6/cEZDzI516DB4OqYckisbAicEEBzSBXc7kwPiJNMJgD vNi4DG8GNuYgSsx1Xgp3OdrnCsLU8aC30FmK9cUrkhkuILRKwP2W90ZQGsuSyPjNP5zk 5E4KJrZkhuaMAiD5fKmA/EYpkoHDnKV5VO1lrqCTNEDb7afV/QBdLqrSkfwlThvnyYmT 755Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q27si7571126eja.643.2020.07.03.02.55.10; Fri, 03 Jul 2020 02:55:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726325AbgGCJwC (ORCPT + 99 others); Fri, 3 Jul 2020 05:52:02 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:7369 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726287AbgGCJv6 (ORCPT ); Fri, 3 Jul 2020 05:51:58 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 68A429C50DBA215F809C; Fri, 3 Jul 2020 17:51:49 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Fri, 3 Jul 2020 17:51:41 +0800 From: Chao Yu To: CC: , , , Dehe Gu , Daiyue Zhang , Chao Yu Subject: [PATCH] f2fs: remove write attribute of main_blkaddr sysfs node Date: Fri, 3 Jul 2020 17:51:29 +0800 Message-ID: <20200703095129.51276-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dehe Gu Fuzzing main_blkaddr sysfs node will corrupt this field's value, causing kernel panic, remove its write attribute to avoid potential security risk. [Chao Yu: add description] Signed-off-by: Dehe Gu Signed-off-by: Daiyue Zhang Reviewed-by: Chao Yu --- fs/f2fs/sysfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 64bbe0b3b830..0b7aa7acd9ec 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -224,6 +224,13 @@ static ssize_t avg_vblocks_show(struct f2fs_attr *a, } #endif +static ssize_t main_blkaddr_show(struct f2fs_attr *a, + struct f2fs_sb_info *sbi, char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%llu\n", + (unsigned long long)MAIN_BLKADDR(sbi)); +} + static ssize_t f2fs_sbi_show(struct f2fs_attr *a, struct f2fs_sb_info *sbi, char *buf) { @@ -525,7 +532,6 @@ F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_idle, gc_mode); F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_urgent, gc_mode); F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments); -F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, main_blkaddr, main_blkaddr); F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards); F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, discard_granularity, discard_granularity); F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks); @@ -568,6 +574,7 @@ F2FS_GENERAL_RO_ATTR(current_reserved_blocks); F2FS_GENERAL_RO_ATTR(unusable); F2FS_GENERAL_RO_ATTR(encoding); F2FS_GENERAL_RO_ATTR(mounted_time_sec); +F2FS_GENERAL_RO_ATTR(main_blkaddr); #ifdef CONFIG_F2FS_STAT_FS F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_foreground_calls, cp_count); F2FS_STAT_ATTR(STAT_INFO, f2fs_stat_info, cp_background_calls, bg_cp_count); -- 2.26.2