Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2848710pxv; Mon, 12 Jul 2021 03:29:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5nNR2z5cwNeM0Q04bvK0/jeIsd5AeEszTFynIdmi8mtg2I45+jOOmx3CaziqbEvz9kSde X-Received: by 2002:a05:6e02:114e:: with SMTP id o14mr37011890ill.201.1626085741593; Mon, 12 Jul 2021 03:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626085741; cv=none; d=google.com; s=arc-20160816; b=XYn72CAK9YZA5M9y9H44SLJzTQLThYexNnb8t+tR6756V7XLV5VX4VN/j9lEhSxxcz mAG+dBGFB67wunyYoiZKRjV7OY+PsXzKHDm+lkvLtxM+9EzrT5Oli0t2EPf4aXq4nkcS yxb62tXUq843sPJPFh3izz3kdkT8kNT1TQqncw+p3Uagqnm/tuVnFnkLG+c3Mkv1OU4n 3ycF7/3k6LZKZf4xvVcuI0FzL7XzNf0wrYXw9rIPjLNXE41mqYWmxc/rD1g9xtv71+SA J7Dj8JEag2AcvQH0Gjuo7jBc+MoSB7zKD9Ld0BABcs4uHNAX/ZWg8Q18W6eOBP8QNmvb D0eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IRp2mf2sgfcF7o2smSvRbNvzAin1cAmdo0cL1mJG+oM=; b=jWV/0aLQMfUxh+IOuc+PjxcQcUcSGGn6oztYinJvARn4YA8b3qI0BjmM0vRpwIguc4 U/Uj0cDdrm30JGYQ33AESh6ZjR7CfRZNw3VtNbKGcfnHCuNnKv3V5H1h6860DZjZHOE/ M7QAQAfBvD7ot2Nqrou/tpvts2T41CCAp6czXt4vZ37/THxTaw6RtmQvgOcmV3KnF5/x 0Rew2bPw50YTqZ0xKRZtlwkhk9ea95cuoZeGh2yopgg/n70TugMD9YS/Y+rrGaUsZNI5 +Ky2LJ6Sv2o5uw6Cz3FltYoN0QjTGMnJ44tYOE3tdGypw1Cv2S7LqjD0T3CJ37jSfONP Tqzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QB3QkrqF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l12si16688932iln.39.2021.07.12.03.28.49; Mon, 12 Jul 2021 03:29:01 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QB3QkrqF; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345507AbhGLHnx (ORCPT + 99 others); Mon, 12 Jul 2021 03:43:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:46256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242309AbhGLHLy (ORCPT ); Mon, 12 Jul 2021 03:11:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 797B1610E5; Mon, 12 Jul 2021 07:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626073745; bh=UoMWSaHmsiLkyCS3/3rlh/pcsEnwbkaIGYNpP5zEEzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QB3QkrqF9BCvYAzPZcR6dJ7l2OGOr/v7bYoAQwiCwPuWsJiNXIXRlN3eklP1Pr6Oa Rgxw1tLnUoioaUbU/3HRb0U1KX411fSeo9QgQZSuP+dyUcqEKl02Z+UdnnwEWO429R kh00cketvgtN2Mst3jXw0/0iN9Xx9B1Ur/bvpkk8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Joseph Qi , Mark Fasheh , Joel Becker , Junxiao Bi , Changwei Ge , Gang He , Jun Piao , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.12 343/700] ocfs2: fix snprintf() checking Date: Mon, 12 Jul 2021 08:07:06 +0200 Message-Id: <20210712061012.774585938@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter [ Upstream commit 54e948c60cc843b6e84dc44496edc91f51d2a28e ] The snprintf() function returns the number of bytes which would have been printed if the buffer was large enough. In other words it can return ">= remain" but this code assumes it returns "== remain". The run time impact of this bug is not very severe. The next iteration through the loop would trigger a WARN() when we pass a negative limit to snprintf(). We would then return success instead of -E2BIG. The kernel implementation of snprintf() will never return negatives so there is no need to check and I have deleted that dead code. Link: https://lkml.kernel.org/r/20210511135350.GV1955@kadam Fixes: a860f6eb4c6a ("ocfs2: sysfile interfaces for online file check") Fixes: 74ae4e104dfc ("ocfs2: Create stack glue sysfs files.") Signed-off-by: Dan Carpenter Reviewed-by: Joseph Qi Cc: Mark Fasheh Cc: Joel Becker Cc: Junxiao Bi Cc: Changwei Ge Cc: Gang He Cc: Jun Piao Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/ocfs2/filecheck.c | 6 +----- fs/ocfs2/stackglue.c | 8 ++------ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/fs/ocfs2/filecheck.c b/fs/ocfs2/filecheck.c index 50f11bfdc8c2..82a3edc4aea4 100644 --- a/fs/ocfs2/filecheck.c +++ b/fs/ocfs2/filecheck.c @@ -328,11 +328,7 @@ static ssize_t ocfs2_filecheck_attr_show(struct kobject *kobj, ret = snprintf(buf + total, remain, "%lu\t\t%u\t%s\n", p->fe_ino, p->fe_done, ocfs2_filecheck_error(p->fe_status)); - if (ret < 0) { - total = ret; - break; - } - if (ret == remain) { + if (ret >= remain) { /* snprintf() didn't fit */ total = -E2BIG; break; diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c index a191094694c6..03eacb249f37 100644 --- a/fs/ocfs2/stackglue.c +++ b/fs/ocfs2/stackglue.c @@ -502,11 +502,7 @@ static ssize_t ocfs2_loaded_cluster_plugins_show(struct kobject *kobj, list_for_each_entry(p, &ocfs2_stack_list, sp_list) { ret = snprintf(buf, remain, "%s\n", p->sp_name); - if (ret < 0) { - total = ret; - break; - } - if (ret == remain) { + if (ret >= remain) { /* snprintf() didn't fit */ total = -E2BIG; break; @@ -533,7 +529,7 @@ static ssize_t ocfs2_active_cluster_plugin_show(struct kobject *kobj, if (active_stack) { ret = snprintf(buf, PAGE_SIZE, "%s\n", active_stack->sp_name); - if (ret == PAGE_SIZE) + if (ret >= PAGE_SIZE) ret = -E2BIG; } spin_unlock(&ocfs2_stack_lock); -- 2.30.2