From patchwork Fri Dec 8 00:41:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 13484529 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4BC1713 for ; Thu, 7 Dec 2023 16:42:26 -0800 (PST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 544EE1FD7D; Fri, 8 Dec 2023 00:42:25 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D271113722; Fri, 8 Dec 2023 00:42:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id U0rnGm5mcmWtAgAAD6G6ig (envelope-from ); Fri, 08 Dec 2023 00:42:22 +0000 From: David Disseldorp To: David Sterba Cc: linux-btrfs@vger.kernel.org, Qu Wenruo , David Disseldorp Subject: [PATCH] btrfs: validate scrub_speed_max sysfs string Date: Fri, 8 Dec 2023 11:41:56 +1100 Message-Id: <20231208004156.9612-1-ddiss@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231207135522.GX2751@twin.jikos.cz> References: <20231207135522.GX2751@twin.jikos.cz> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spam-Score: -4.00 X-Spam-Flag: NO X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd1 X-Spam-Level: X-Rspamd-Queue-Id: 544EE1FD7D X-Spam-Score: -4.00 Fail the sysfs I/O on any trailing non-space characters. Signed-off-by: David Disseldorp Reviewed-by: Qu Wenruo --- fs/btrfs/sysfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index e6b51fb3ddc1e..4c4642ef7c5f0 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1783,6 +1783,9 @@ static ssize_t btrfs_devinfo_scrub_speed_max_store(struct kobject *kobj, unsigned long long limit; limit = memparse(buf, &endptr); + endptr = skip_spaces(endptr); + if (*endptr != 0) + return -EINVAL; WRITE_ONCE(device->scrub_speed_max, limit); return len; }