Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp658146pxb; Tue, 5 Apr 2022 17:36:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCwB+seI4RzCLHXSSbWA+ImDYL6VbyJb3E5g8HiIUZoEhLG2/c+9hc0jxUvVDQYnny9ZcZ X-Received: by 2002:aa7:d311:0:b0:419:443b:6222 with SMTP id p17-20020aa7d311000000b00419443b6222mr6093767edq.161.1649205339718; Tue, 05 Apr 2022 17:35:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649205339; cv=none; d=google.com; s=arc-20160816; b=PwresUqz7180vVs0tFUgYa0Yi5x1e0A0BGDbpp2UcgTP1JU/+i0/5smtxiSqklPGjn qGnJZnsqI8GN9b4nccjI1vcwIa+ah48B3vMnhgXQ9CDg9tL6A2KdNuYohmwX+F4JhuLa HhXU4yT+uqKaOwqPXjp4FtjuZr2Ijiw/1nfen572FA+v9Z7vtntS6AQGcE9N0GyNsfNy pQRofgy1Aw485/TVlZETnZN+O4PIJLwrwG+B0eOlMRctCODdoXA+mHue0AEFKTIeoWwh B8T5+IWySp2erJzNP/b9dJNEvdIwVrVspCwKQhGuXH5i2rtdP0ANhfl/rcdIs2k23tim 7AGQ== 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=U3hc7vNYrXn162gnaFtmFp1oayl7LAPvN23SIpQc678=; b=v91/FiejR5Yr05BgAUvBZSaNtoJMLRxOauKIuQuRXanN7eLEwHOK6oyRznzZ3CgetM 5JbiafDwAiUTLSZHxQLBmcBbnhSeXKfPL6m9D7bWbPMp0azVoWtKt2L5PDnSJBpAMCj2 77V4IQyZKEr3LaePAcJivKPZfrSKHtljCsAfIuuE1sSOS4PSrmoy08CNZryIiXQGfcPd nYUTjIiOkkaTVGxNHJ+8LWwoWOjzXhYJBOqbZjttMNIeB4H0WdBzJoO2Pnh3DaCCZyy5 IZWNw/7g84UNgi3HQ6np62wJiacyrw4U0BovPhi6jzYfWnwHDbcbrIX7JfAGu79RtG9A VwQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ULaeXfmO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m10-20020a056402510a00b00418c2b5be19si12096985edd.251.2022.04.05.17.35.14; Tue, 05 Apr 2022 17:35:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ULaeXfmO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1387366AbiDENPE (ORCPT + 99 others); Tue, 5 Apr 2022 09:15:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344257AbiDEJTC (ORCPT ); Tue, 5 Apr 2022 05:19:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DEDE4992D; Tue, 5 Apr 2022 02:06:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2E6AFB81B75; Tue, 5 Apr 2022 09:06:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EBDAC385A1; Tue, 5 Apr 2022 09:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149582; bh=8IQB+YCfSpDf96JH1d8nrwhqf/Z8XCqWA/juA9C6MN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ULaeXfmOfSObz2AoyIB5DUO3VVz+cIY+reC44FmiA3iMWmg2C/dDNtRyL73ufSPfB i0jCQ/YPMbf5mmuS+D5Jqb8GNySClYPZSrsmncveWO0Vb+cqLwnbOYktGFZYMWVWEP 0ogY0dcdagbYcdKI2qfZImgjwjF9Bbfh2CPWlFh4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chaitanya Kulkarni , Himanshu Madhani , Jens Axboe , Sasha Levin Subject: [PATCH 5.16 0768/1017] loop: use sysfs_emit() in the sysfs xxx show() Date: Tue, 5 Apr 2022 09:28:01 +0200 Message-Id: <20220405070417.057578042@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chaitanya Kulkarni [ Upstream commit b27824d31f09ea7b4a6ba2c1b18bd328df3e8bed ] sprintf does not know the PAGE_SIZE maximum of the temporary buffer used for outputting sysfs content and it's possible to overrun the PAGE_SIZE buffer length. Use a generic sysfs_emit function that knows the size of the temporary buffer and ensures that no overrun is done for offset attribute in loop_attr_[offset|sizelimit|autoclear|partscan|dio]_show() callbacks. Signed-off-by: Chaitanya Kulkarni Reviewed-by: Himanshu Madhani Link: https://lore.kernel.org/r/20220215213310.7264-2-kch@nvidia.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/loop.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index fdb4798cb006..1422967bf5c1 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -681,33 +681,33 @@ static ssize_t loop_attr_backing_file_show(struct loop_device *lo, char *buf) static ssize_t loop_attr_offset_show(struct loop_device *lo, char *buf) { - return sprintf(buf, "%llu\n", (unsigned long long)lo->lo_offset); + return sysfs_emit(buf, "%llu\n", (unsigned long long)lo->lo_offset); } static ssize_t loop_attr_sizelimit_show(struct loop_device *lo, char *buf) { - return sprintf(buf, "%llu\n", (unsigned long long)lo->lo_sizelimit); + return sysfs_emit(buf, "%llu\n", (unsigned long long)lo->lo_sizelimit); } static ssize_t loop_attr_autoclear_show(struct loop_device *lo, char *buf) { int autoclear = (lo->lo_flags & LO_FLAGS_AUTOCLEAR); - return sprintf(buf, "%s\n", autoclear ? "1" : "0"); + return sysfs_emit(buf, "%s\n", autoclear ? "1" : "0"); } static ssize_t loop_attr_partscan_show(struct loop_device *lo, char *buf) { int partscan = (lo->lo_flags & LO_FLAGS_PARTSCAN); - return sprintf(buf, "%s\n", partscan ? "1" : "0"); + return sysfs_emit(buf, "%s\n", partscan ? "1" : "0"); } static ssize_t loop_attr_dio_show(struct loop_device *lo, char *buf) { int dio = (lo->lo_flags & LO_FLAGS_DIRECT_IO); - return sprintf(buf, "%s\n", dio ? "1" : "0"); + return sysfs_emit(buf, "%s\n", dio ? "1" : "0"); } LOOP_ATTR_RO(backing_file); -- 2.34.1