From nobody Wed Mar 9 15:35:48 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4052A19F52CD; Wed, 9 Mar 2022 15:35:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KDGVr5rYPz4TnB; Wed, 9 Mar 2022 15:35:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646840148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S/FnNLexyvRKLQajpmvSM+JidGffuo47PUL83HroNQ4=; b=yMDJjZL/WPpddwHfi57r0lroDwh2JNvaxqp8griQQG7giM32uO/USIpoyGmJsNHPbCbbHc 2Hm508fFAI0N54CIdyKoqJoMkafRqDzHTJvjNKE8qPBxcdIzEWh3didQArogt/mnqSpZq5 xZfB9ArcIUCp6NS6tm1Ev2spyJtr2b5b/ruNTTctBko9ayVhZcuL0nK3TJm5Zd04fJdhYL w+H2lk5oj9CUKPDXIHooqe6yppetrQybNuRYOBZrMR8Gh0352UHsPpTRviaEml56Ui1Oz0 7hWg/IDhCx+DslEe5/o/dy+52Fjy5LOr5y/p+ZaczMI6YrbkANTXjOppgF6MBA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8530B13993; Wed, 9 Mar 2022 15:35:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 229FZm37031970; Wed, 9 Mar 2022 15:35:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 229FZmPS031969; Wed, 9 Mar 2022 15:35:48 GMT (envelope-from git) Date: Wed, 9 Mar 2022 15:35:48 GMT Message-Id: <202203091535.229FZmPS031969@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mike Karels Subject: git: c0d9004101db - stable/13 - Add serial-number to hw.fdt sysctl area if found in fdt. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: karels X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c0d9004101dbd9637a6b7e1b876f8eece489a5cf Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646840148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S/FnNLexyvRKLQajpmvSM+JidGffuo47PUL83HroNQ4=; b=dAifjaiNucCecmMEGM6UAk4kOpPTUaYLd/lP3zV79EmSBDqjdfHeqM5c4QjSDnxf9Q/Dd+ r0GLQZRVN17S5SqddY6ctSyL4h3V8732bn/IfGI0EzzzYFB/6NXDNGaHHrYvFzlzCXJGOP 0X6pZZfyClqLu4qURBYYAEMukElJYlnFlQGXg60rwe7WnG2k5Ifa9F49hWd9hSJCHUdYdR f6Wo+WshyOzsuIfWig+SAh9fbmhM1EhmO+IeDpupWvGUgHVpR+l5OrY75wwn+jrpg53SCR YaUvgapi3tYKPE/k0QQ4L8XU01CNQyAwkj5m4yI/YAERP0CVy5zY7e3KCtm+TA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646840148; a=rsa-sha256; cv=none; b=oVWB8mno48fkfSLTHDZafoP+BhvMxJ952cV5g1Uf0Mv98wqszKQlaD1XytaePDQXDXjeBj GO7CPnmRt+gGCCAhB3IKdURwzY0UwJzCOI1y7p8U620RKozCjHT9nM6/D+mMBdtG/XJHAA nJ5UllQeZ5m9Y5N1HHr7cnzFdLK9tueQPps7hxN/aZU+KYmtNEMumjBVH69zf08eBH8ko4 xSXDxKinlAdJdXW+76HdSf4gv9JdNz6yixFB+EL974kXvZjwCYXq2RqLiCG1W/bhwSXI20 RfZ0CCjd3i3x1zl18v37jaBSabzmxj/Un/PeFVnNvAuBXV0cHha2D3oBCSpmcg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by karels: URL: https://cgit.FreeBSD.org/src/commit/?id=c0d9004101dbd9637a6b7e1b876f8eece489a5cf commit c0d9004101dbd9637a6b7e1b876f8eece489a5cf Author: Mike Karels AuthorDate: 2022-02-23 20:42:30 +0000 Commit: Mike Karels CommitDate: 2022-03-09 15:28:28 +0000 Add serial-number to hw.fdt sysctl area if found in fdt. Add serial-number sysctl if that fdt property exists and is a printable string. While here, ensure that the hw.fdt sysctl values fit in the buffers provided so that they will be NUL-terminated. Tested on Raspberry Pi 3B+ and 4. Reviewed by: manu imp Differential Revision: https://reviews.freebsd.org/D34356 (cherry picked from commit b8b0c65e8a43cab95b97e28d3e3d73fc7d9c0a5e) --- sys/dev/ofw/ofw_fdt.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/sys/dev/ofw/ofw_fdt.c b/sys/dev/ofw/ofw_fdt.c index a83f7cbdcb60..855bf6d5d14a 100644 --- a/sys/dev/ofw/ofw_fdt.c +++ b/sys/dev/ofw/ofw_fdt.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -107,11 +108,13 @@ OFW_DEF(ofw_fdt); #define FDT_FBSDVER_LEN 16 #define FDT_MODEL_LEN 80 #define FDT_COMPAT_LEN 255 +#define FDT_SERIAL_LEN 32 static void *fdtp = NULL; static char fdt_model[FDT_MODEL_LEN]; static char fdt_compatible[FDT_COMPAT_LEN]; static char fdt_fbsd_version[FDT_FBSDVER_LEN]; +static char fdt_serial[FDT_SERIAL_LEN]; static int sysctl_handle_dtb(SYSCTL_HANDLER_ARGS) @@ -143,6 +146,10 @@ sysctl_register_fdt_oid(void *arg) SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), OID_AUTO, "freebsd-version", CTLFLAG_RD, fdt_fbsd_version, FDT_FBSDVER_LEN, "FreeBSD DTS branding version"); + if (fdt_serial[0] != '\0') + SYSCTL_ADD_STRING(NULL, SYSCTL_STATIC_CHILDREN(_hw_fdt), + OID_AUTO, "serial-number", CTLFLAG_RD, fdt_serial, + FDT_SERIAL_LEN, "Serial number"); } SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, NULL); @@ -161,20 +168,44 @@ ofw_fdt_init(ofw_t ofw, void *data) fdtp = data; root = ofw_fdt_finddevice(NULL, "/"); len = ofw_fdt_getproplen(NULL, root, "model"); - bzero(fdt_model, FDT_MODEL_LEN); - ofw_fdt_getprop(NULL, root, "model", fdt_model, FDT_MODEL_LEN); + if (len > 0 && len <= FDT_MODEL_LEN) { + bzero(fdt_model, FDT_MODEL_LEN); + ofw_fdt_getprop(NULL, root, "model", fdt_model, FDT_MODEL_LEN); + } len = ofw_fdt_getproplen(NULL, root, "compatible"); - bzero(fdt_compatible, FDT_COMPAT_LEN); - ofw_fdt_getprop(NULL, root, "compatible", fdt_compatible, FDT_COMPAT_LEN); - /* Replace the middle '\0' with ' ' */ - for (i = 0; i < len - 1; i++) - if (fdt_compatible[i] == '\0') - fdt_compatible[i] = ' '; - if ((len = ofw_fdt_getproplen(NULL, root, "freebsd,dts-version")) > 0) { + if (len > 0 && len <= FDT_COMPAT_LEN) { + bzero(fdt_compatible, FDT_COMPAT_LEN); + ofw_fdt_getprop(NULL, root, "compatible", fdt_compatible, + FDT_COMPAT_LEN); + /* Replace the middle '\0' with ' ' */ + for (i = 0; i < len - 1; i++) + if (fdt_compatible[i] == '\0') + fdt_compatible[i] = ' '; + } + len = ofw_fdt_getproplen(NULL, root, "freebsd,dts-version"); + if (len > 0 && len <= FDT_FBSDVER_LEN) { bzero(fdt_fbsd_version, FDT_FBSDVER_LEN); ofw_fdt_getprop(NULL, root, "freebsd,dts-version", fdt_fbsd_version, FDT_FBSDVER_LEN); } + len = ofw_fdt_getproplen(NULL, root, "serial-number"); + if (len > 0 && len <= FDT_SERIAL_LEN) { + bzero(fdt_serial, FDT_SERIAL_LEN); + ofw_fdt_getprop(NULL, root, "serial-number", + fdt_serial, FDT_SERIAL_LEN); + /* + * Non-standard property; check for NUL-terminated + * printable string. + */ + for (i = 0; i < len - 1; i++) { + if (!isprint(fdt_serial[i])) { + fdt_serial[0] = '\0'; + break; + } + } + if (fdt_serial[len - 1] != '\0') + fdt_serial[0] = '\0'; + } return (0); }