Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6147222iog; Thu, 23 Jun 2022 12:19:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1veUjC9K0ytuPDz6syv6X/DnPkRiKTsjJqGggaOmsIphip3lK1ONBokGUdh7CgfR2F+/MOR X-Received: by 2002:a05:6a00:2444:b0:4fd:db81:cbdd with SMTP id d4-20020a056a00244400b004fddb81cbddmr41820764pfj.32.1656011952128; Thu, 23 Jun 2022 12:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011952; cv=none; d=google.com; s=arc-20160816; b=hEjRDMr0bmcQj3GvTBv0MiOGgdNLayH+Z3PB28yyevYA4VO3Pkb5Q3Ak3QSynKu3Up 8VmcUuNs95iTDOspoIWa3Gyv0679DJiU39LAIQYpUzVuvgsogjlf1DaCI7fPbbV7qj3+ /CHW4WfHTvGDKrk9grkFsqDl0nUX3S0fxOyvyc/fkH/fB5hfbt6kJsfmS1fcosY1EEMh i6/Ept0yzf9cUrXVsUEY9d/yQabLO3FNVRQd6tYZF3pajqIs9RB7lk8wlCPcFFC9/4YN nEOvi3kLqI+EFbhdzsJyPxjWp3yuIC6Y7G3082IBhZbjmd/UpTdbALAi2n1YSjfG66ij fOyg== 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=1zW1xqBzsbDdQrRKNG3TrhoI5Q1egg3jFvwV/BFA8RA=; b=AtpSJaML6y/wXvmAgszPEB7AAUvGTEW2572p9L7jQMwuRHelGR10hnbfsI7SWhpDGH QIaZMICP2jGjV/K0hBp4Dg38MPtMSvkU+6JjBGi6Wuphs2iJhMytxB1Z1tgsjvKi4aS0 4htJyMmXIcULPSadiGxH3WQk6qqnPgeHbPv+vhIgZJC46JzJXWqw46NdQeFwAZyfVfnA cQDWfq1wlUiR1M5/rfETyqebpqjQUHTZ3edAIN+Dvw+1trX9bU6JT2gZjgc/9dNlPWEw YTylxc9mPvCPSZf6qAmxw+v69a8xj+eGXdgBm6+Y9b3lqy2vhx/aAaqcexZJ9snEyUt/ cuHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pwoy6Orr; 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 j3-20020a170903028300b0016a1f3f7c57si368939plr.607.2022.06.23.12.19.00; Thu, 23 Jun 2022 12:19:12 -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=pwoy6Orr; 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 S235949AbiFWSGr (ORCPT + 99 others); Thu, 23 Jun 2022 14:06:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235935AbiFWSF4 (ORCPT ); Thu, 23 Jun 2022 14:05:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42182B48D; Thu, 23 Jun 2022 10:17:57 -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 dfw.source.kernel.org (Postfix) with ESMTPS id CBB9061DE5; Thu, 23 Jun 2022 17:17:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 867EEC3411B; Thu, 23 Jun 2022 17:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004676; bh=DJOfc8IEF1VN/EqCHdagr52Mi4FS6cladU3yklwt0is=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pwoy6OrrEDYqmUroifblvvUA9UPLQEXk2vd+mqyiwC/nJYJmmP/eJzLY74YdFL/EI NkoGvCXeSt07c3A8h4CUVs/j9PW3SHZ+37dccUodxc8u5sZg7kimKq9ojzQVBJApix czv9mEMo47mrN0eJYPHeDdeNRTEmjMm9AQjPcDi4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominik Brodowski , "Jason A. Donenfeld" Subject: [PATCH 4.19 113/234] random: cleanup UUID handling Date: Thu, 23 Jun 2022 18:43:00 +0200 Message-Id: <20220623164346.255917163@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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.7 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: "Jason A. Donenfeld" commit 64276a9939ff414f2f0db38036cf4e1a0a703394 upstream. Rather than hard coding various lengths, we can use the right constants. Strings should be `char *` while buffers should be `u8 *`. Rather than have a nonsensical and unused maxlength, just remove it. Finally, use snprintf instead of sprintf, just out of good hygiene. As well, remove the old comment about returning a binary UUID via the binary sysctl syscall. That syscall was removed from the kernel in 5.5, and actually, the "uuid_strategy" function and related infrastructure for even serving it via the binary sysctl syscall was removed with 894d2491153a ("sysctl drivers: Remove dead binary sysctl support") back in 2.6.33. Reviewed-by: Dominik Brodowski Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1654,22 +1654,25 @@ const struct file_operations urandom_fop static int sysctl_random_min_urandom_seed = 60; static int sysctl_random_write_wakeup_bits = POOL_MIN_BITS; static int sysctl_poolsize = POOL_BITS; -static char sysctl_bootid[16]; +static u8 sysctl_bootid[UUID_SIZE]; /* * This function is used to return both the bootid UUID, and random - * UUID. The difference is in whether table->data is NULL; if it is, + * UUID. The difference is in whether table->data is NULL; if it is, * then a new UUID is generated and returned to the user. - * - * If the user accesses this via the proc interface, the UUID will be - * returned as an ASCII string in the standard UUID format; if via the - * sysctl system call, as 16 bytes of binary data. */ static int proc_do_uuid(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { - struct ctl_table fake_table; - unsigned char buf[64], tmp_uuid[16], *uuid; + u8 tmp_uuid[UUID_SIZE], *uuid; + char uuid_string[UUID_STRING_LEN + 1]; + struct ctl_table fake_table = { + .data = uuid_string, + .maxlen = UUID_STRING_LEN + }; + + if (write) + return -EPERM; uuid = table->data; if (!uuid) { @@ -1684,12 +1687,8 @@ static int proc_do_uuid(struct ctl_table spin_unlock(&bootid_spinlock); } - sprintf(buf, "%pU", uuid); - - fake_table.data = buf; - fake_table.maxlen = sizeof(buf); - - return proc_dostring(&fake_table, write, buffer, lenp, ppos); + snprintf(uuid_string, sizeof(uuid_string), "%pU", uuid); + return proc_dostring(&fake_table, 0, buffer, lenp, ppos); } extern struct ctl_table random_table[]; @@ -1725,13 +1724,11 @@ struct ctl_table random_table[] = { { .procname = "boot_id", .data = &sysctl_bootid, - .maxlen = 16, .mode = 0444, .proc_handler = proc_do_uuid, }, { .procname = "uuid", - .maxlen = 16, .mode = 0444, .proc_handler = proc_do_uuid, },