From: Dongliang Mu Date: Tue, 28 Jun 2022 13:59:48 +0800 Subject: [Cluster-devel] [PATCH] gfs2: fix overread in the strlcpy of init_names Message-ID: <20220628055949.566089-1-dzm91@hust.edu.cn> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit From: Dongliang Mu In init_names, strlcpy will overread the src string as the src string is less than GFS2_FSNAME_LEN(256). Fix this by modifying strlcpy back to snprintf, reverting the commit 00377d8e3842. Fixes: 00377d8e3842 ("[GFS2] Prefer strlcpy() over snprintf()") Reported-by: syzkaller Signed-off-by: Dongliang Mu --- fs/gfs2/ops_fstype.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index c9b423c874a3..ee29b50d39b9 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -383,8 +383,8 @@ static int init_names(struct gfs2_sbd *sdp, int silent) if (!table[0]) table = sdp->sd_vfs->s_id; - strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN); - strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN); + snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto); + snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table); table = sdp->sd_table_name; while ((table = strchr(table, '/'))) -- 2.35.1