Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp924626pxb; Wed, 6 Apr 2022 04:26:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzV7XrWpNT9O7Nrv1uLm1KPwDt/ZvlCfOn2iKZv/w50e5rCSK4E/aKY2pjMOjEVUMI91N8 X-Received: by 2002:a17:902:ccc1:b0:156:6066:bd18 with SMTP id z1-20020a170902ccc100b001566066bd18mr8169177ple.28.1649244418244; Wed, 06 Apr 2022 04:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649244418; cv=none; d=google.com; s=arc-20160816; b=rbb3YfWuW2ukw8S8ZISaRrj96zOf9B0m9KPA5o+JY1mN2HxYtZwpO7ANWlGDYdDWTn W9nLqua2cKmWBGxODP2epxrBlD6ez5LKHd3xsAI9VwnalpoeF40OT9mBnkvibrWA1lF9 pPpQZdQ51mXjMPAn0Mv8LNYG0fY3fl8ReKA4/dj2Ss9Ci03wGcuVHflvfDNsW+l6SIJB EianCzTUZebf5RH1sZFrdkzQZfPfXNiLawzkMk9MffxqWwSkmtDqUYgqk39e4DcmxyR/ j9iAnIY/joa8CZPpBHPsUU53DiGhfj0V/gXUf+2+CAA5q04uWhhsXUH9MmQCQIUypuP2 wR5w== 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=JpOQiR5lpIcXzraf4ZqyTgbilyyX6fsTZ5rqkepAawY=; b=fY4Qorm17VgvkKVSl/sp61nViiJSNenD5KE6OyBuYWpIgJjZPRaxzNrbUWOUm7/9tq wvyzfx/PlMnVThAtSIR6hMTDwfsAjSwItecJLDHJbQ2w6X3STiV6TscAtMhpKZgDeY+c 6llz6FAZpEYOfcdFhkeaxXKM/5I+hSxGrLJ/UcJAi6gl2OlbqZXxX81tUWCNswyJ2oYc mJwJMECAUNwlwt76QIHWtsr6UlCcw4L+muDUINyCDLTB2fHOySNuzY2/nKGQbWfBMyip zTPlFx2Rf4EpWPd0waeeEOedPlOvycOomQotApqTUbpvwq4DdBu7Tl/KQI9izH5SBtEQ Kmvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="NU/GbBC6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id mw11-20020a17090b4d0b00b001c361252184si5020938pjb.141.2022.04.06.04.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:26:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="NU/GbBC6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 392B846A0EE; Wed, 6 Apr 2022 02:49:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1576682AbiDFANm (ORCPT + 99 others); Tue, 5 Apr 2022 20:13:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349977AbiDEJwO (ORCPT ); Tue, 5 Apr 2022 05:52:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DB9735266; Tue, 5 Apr 2022 02:50:16 -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 C26B6B818F3; Tue, 5 Apr 2022 09:50:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19D36C385A2; Tue, 5 Apr 2022 09:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152213; bh=Y9vz61kRi+0D0+pc4M6WJIazZc8SD+yi8M25hfH4qzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NU/GbBC6KnPuBYMFslaBhAtOhIZfmUYk7QgqBZH3IW1b0V7SHbj/kH/y9HAQ8ZeWP 99HBkJtd1EOeyvCUwQC/gctrhyCSVHwOnRk6Z7PkJW8HVfxFgMZbIUHXe4H3papVug 6bvBcflMyWt/VHtrjI7EPMNV+FYg0Qf5EnfhVhRk= 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.15 695/913] loop: use sysfs_emit() in the sysfs xxx show() Date: Tue, 5 Apr 2022 09:29:17 +0200 Message-Id: <20220405070400.667499909@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 92f9d32bfae5..8cba10aafadb 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -844,33 +844,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