Bug 262369 - Linuxulator: add /proc/sys/kernel/random/boot_id
Summary: Linuxulator: add /proc/sys/kernel/random/boot_id
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: amd64 Any
: --- Affects Many People
Assignee: Fernando Apesteguía
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-03-05 22:21 UTC by Sami Halabi
Modified: 2022-06-17 19:42 UTC (History)
6 users (show)

See Also:


Attachments
Patch to the kernel (1.04 KB, patch)
2022-03-08 14:19 UTC, Fernando Apesteguía
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sami Halabi 2022-03-05 22:21:15 UTC
Linuxulator is great. however it has:
/proc/sys/kernel/random/uuid
which basically emulates boot_id for linux, but many programs refer to :
/proc/sys/kernel/random/boot_id

i tried to symlink (ln -s  /proc/sys/kernel/random/uuid  /proc/sys/kernel/random/boot_id) but it seems a redonly dir

I think this should be added for linux compatibility or create also boot_id file (with the same value?)

can it (symlink or file) added this for linuxulator compatibility with linux?

Sami
Comment 1 Sami Halabi 2022-03-05 22:28:27 UTC
btw: its about linprocfs!

also
as stated in: https://www.kernel.org/doc/html/latest/admin-guide/sysctl/kernel.html#random

uuid should be regenerated everytime its read
and boot_id should be set once

at this point i don't care about the difference but maybe should a maintainer fix this accordingly
Comment 2 Fernando Apesteguía freebsd_committer freebsd_triage 2022-03-08 14:19:50 UTC
Created attachment 232322 [details]
Patch to the kernel

This patch might do it.

Note that the value of boot_id is invariant per mount. Every time linprocfs is remounted, it will take a new value. In Linux procfs is virtually impossible to unmount because it is used continually.
Comment 3 Sami Halabi 2022-03-08 17:37:31 UTC
Hi,
Seems actually to do the trick.. wull try it and report.

If we are here, from What I read uuid should be different each time its read.. is that the case?

Sami
Comment 4 Sami Halabi 2022-03-08 17:40:56 UTC
I went over the code..
You use 'sb' is it a global variable ? Since I don't see where its defined..

Sami
Comment 5 Fernando Apesteguía freebsd_committer freebsd_triage 2022-03-09 07:24:35 UTC
(In reply to Sami Halabi from comment #3)
Yes, uuid is different each time while boot_id is the same (it is generated only for the first access):

[root@vm-current /compat/linux/proc/sys/kernel/random]# while true;do echo "uuid: $(cat uuid)"; echo "boot_id: $(cat boot_id)"; echo "--------"; sleep 1; done
uuid: 137336f7-9f82-11ec-a42a-080027bf0030
boot_id: edf12448-9f81-11ec-a429-080027bf0030
--------
uuid: 141106f9-9f82-11ec-a42a-080027bf0030
boot_id: edf12448-9f81-11ec-a429-080027bf0030
--------
uuid: 14b54806-9f82-11ec-a42a-080027bf0030
boot_id: edf12448-9f81-11ec-a429-080027bf0030
--------
uuid: 155a0fe7-9f82-11ec-a42a-080027bf0030
boot_id: edf12448-9f81-11ec-a429-080027bf0030
--------
uuid: 15f9a439-9f82-11ec-a42a-080027bf0030
boot_id: edf12448-9f81-11ec-a429-080027bf0030
--------
uuid: 169ae638-9f82-11ec-a42a-080027bf0030
boot_id: edf12448-9f81-11ec-a429-080027bf0030
--------
uuid: 173fa178-9f82-11ec-a42a-080027bf0030
boot_id: edf12448-9f81-11ec-a429-080027bf0030
--------
uuid: 17e42d8f-9f82-11ec-a42a-080027bf0030
boot_id: edf12448-9f81-11ec-a429-080027bf0030
--------
Comment 6 Fernando Apesteguía freebsd_committer freebsd_triage 2022-03-09 07:27:25 UTC
(In reply to Sami Halabi from comment #4)

It is one of the arguments of the handler (PFS_FILL_ARGS):

#define PFS_FILL_ARGS \
        struct thread *td, struct proc *p, struct pfs_node *pn, \
        struct sbuf *sb, struct uio *uio

in sys/fs/pseudofs/pseudofs.h

Cheers
Comment 7 Sami Halabi 2022-03-10 19:09:59 UTC
Hi,
Againt what src did you make tge patch.
Currently I have 12.3-R-p2.
As I read tge docs the src for that not maintained, but 12/stable. Right?
Anyway from what I read the patch is doing what its intented to do. Can you yiu push it so freebsd-update would pick it up?
Thanks in advance,
Sami
Comment 8 John Hein 2022-03-10 21:21:17 UTC
Note that the linux implementation of these is random, whereas the the freebsd linuxulator implementation is not:

for ii in 1 2 3 4 ; do cat /compat/linux/proc/sys/kernel/random/uuid ; done
d5491552-a0b6-11ec-a963-90b11c7011ef
d5495a75-a0b6-11ec-a963-90b11c7011ef
d5497ded-a0b6-11ec-a963-90b11c7011ef
d549b78d-a0b6-11ec-a963-90b11c7011ef

One might consider this a deficiency or just an idiosyncratic difference between linux and linuxulator.  But if it is a deficiency, this is a separate bug.  I only made a comment here instead of opening a bug since I'm not sure if I would call it a bug.  I guess I lean toward deficiency as the linux random(4) page that documents these files (uuid & boot_id) says "These read-only files contain random strings ...".  Maybe it's an open question whether people in the "real world" depend on true randomness for these values.
Comment 9 Fernando Apesteguía freebsd_committer freebsd_triage 2022-03-11 06:42:32 UTC
(In reply to Sami Halabi from comment #7)
It is against current. I do not have a base committer. This needs to be reviewed and accepted first. trasz@ in copy since he knows more about Linux emulation.
Comment 10 Fernando Apesteguía freebsd_committer freebsd_triage 2022-03-11 06:45:40 UTC
(In reply to John Hein from comment #8)
An UUID is not truly random (https://en.wikipedia.org/wiki/Universally_unique_identifier#Format) at least until version 4. I suppose, if needed, this could be changed.
Comment 11 Dmitry Chagin freebsd_committer freebsd_triage 2022-04-09 09:59:53 UTC
(In reply to Fernando Apesteguía from comment #9)

Fernando, the patch looks good to me, feel free to put it on a phab, I'll approve
Comment 12 Fernando Apesteguía freebsd_committer freebsd_triage 2022-04-09 17:12:37 UTC
Review: https://reviews.freebsd.org/D34860
Comment 13 commit-hook freebsd_committer freebsd_triage 2022-04-11 16:27:56 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0f2041a5b03259a8a7b20ffc98e34884cc5590b3

commit 0f2041a5b03259a8a7b20ffc98e34884cc5590b3
Author:     Fernando Apesteguía <fernape@FreeBSD.org>
AuthorDate: 2022-03-08 14:19:53 +0000
Commit:     Fernando Apesteguía <fernape@FreeBSD.org>
CommitDate: 2022-04-11 16:23:28 +0000

    [linprocfs] add sys/kernel/random/boot_id

    This file holds a UUID that is invariant for every boot. In our case, it is
    invariant per mount.

    PR:     262369
    Reported by:    sodynet1@gmail.com
    Approved by:    dchagin@
    Differential Revision:  https://reviews.freebsd.org/D34860

 sys/compat/linprocfs/linprocfs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
Comment 14 Fernando Apesteguía freebsd_committer freebsd_triage 2022-04-11 16:29:01 UTC
Committed,

Thanks!
Comment 15 commit-hook freebsd_committer freebsd_triage 2022-06-17 19:42:15 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c43c6efaee52465c1076de3f2ba2d3aef56c5bb7

commit c43c6efaee52465c1076de3f2ba2d3aef56c5bb7
Author:     Fernando Apesteguía <fernape@FreeBSD.org>
AuthorDate: 2022-03-08 14:19:53 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-06-17 19:33:50 +0000

    [linprocfs] add sys/kernel/random/boot_id

    This file holds a UUID that is invariant for every boot. In our case, it is
    invariant per mount.

    PR:     262369
    Reported by:    sodynet1@gmail.com
    Approved by:    dchagin@
    Differential Revision:  https://reviews.freebsd.org/D34860

    (cherry picked from commit 0f2041a5b03259a8a7b20ffc98e34884cc5590b3)

 sys/compat/linprocfs/linprocfs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)