Interface for read info about SD card

Hi.

We are trying to read information about internal SD cards on RPI to predict possible device failures. Is there no way to do this now?
For instance information about manufacturing date is here: /sys/block/mmcblk0/device/date and you can read the information about the name and the manufacturer in the same directory.

I initially thought that block-devices interface would help but when I used it, it turned out that was not helping.

On cat /sys/block/mmcblk0/device/date from inside the snap I am getting the apparmor denial with a following path /sys/devices/platform/soc/3f202000.mmc/mmc_host/mmc0/mmc0:aaaa/date.

Is it possible to do with existing snapd permissions or can a new interface be added for that?

i would expect that udisks2 is able to query such info …

This is a sample output. Unfortunately, there is no vendor id or manufacturing date. Some stuff shows up though indirectly. name of the device is the SC16G, and serial 0xc52340f1 which can be inferred from the id here.

I don’t really care about the id though. What’s more important is is the vendor and the model (oemid and name might be the answer for this I think) to see for what kind of cards there might be a higher chance of failure.

It also gets this info in some other way, unfortunately, so while my snap has the udisks interface and ships udisks inside I can’t access /sys/block/mmcblk0/device/*

/org/freedesktop/UDisks2/drives/SC16G_0xc52340f1:
org.freedesktop.UDisks2.Drive:
CanPowerOff:                false
Configuration:              {}
ConnectionBus:              sdio
Ejectable:                  false
Id:                         SC16G-0xc52340f1
Media:                      flash_sd
MediaAvailable:             true
MediaChangeDetected:        true
MediaCompatibility:         flash_sd
MediaRemovable:             true
Model:                      SC16G
Optical:                    false
OpticalBlank:               false
OpticalNumAudioTracks:      0
OpticalNumDataTracks:       0
OpticalNumSessions:         0
OpticalNumTracks:           0
Removable:                  true
Revision:
RotationRate:               0
Seat:                       seat0
Serial:                     0xc52340f1
SiblingId:
Size:                       15931539456
SortKey:                    00coldplug/12removable/mmcblk0
TimeDetected:               1624919634048947
TimeMediaDetected:          1624919634048947
Vendor:
WWN:

take a look at the raw-volume interface, perhaps that helps …

EDIT: or perhaps block-devices

Yes, I did enable block-devices. I thought it would give me access because of following line:
/dev/mmcblk[0-9]{,[0-9],[0-9][0-9]} rw, # MMC (up to 1000 devices)

cat /sys/block/mmcblk0/device/date

And accessing that causes following app armor denial:

Jun 29 13:37:15 srly-r7d8mg4oj4eo0go kernel: audit: type=1400 audit(1624963035.345:420): apparmor="DENIED" operation="open" profile="snap.screenly-client.submit-report" name="/sys/devices/platform/soc/3f202000.mmc/mmc_host/mmc0/mmc0:aaaa/date" pid=22082 comm="cat" requested_mask="r" denied_mask="r" fsuid=0 ouid=0 Jun 29 13:37:15 srly-r7d8mg4oj4eo0go audit[22082]: AVC apparmor="DENIED" operation="open" profile="snap.screenly-client.submit-report" name="/sys/devices/platform/soc/3f202000.mmc/mmc_host/mmc0/mmc0:aaaa/date" pid=22082 comm="cat" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

Going to test raw-volumes now.

1 Like

Unfortunately, it did not work with either of those interfaces for me. Can this functionality be added to an existing interface?
I am open to writing a patch for it but Idk how generic that access would be as I am just interested in access to this internal SD card storage.

I think the intention for this sort of rule is more reflected by the existing rule:

/sys/devices/**/block/** r,

so to enable what you need for just read access you could try adding a rule to the block-devices interface for :

/sys/devices/platform/soc/**/mmc_host/** r,

We could probably make it more generic since it’s read only but this seems sufficiently specific to mmc devices that would also be block devices

Tested it on a device and confirmed that helps. Created PR - https://github.com/snapcore/snapd/pull/10491

1 Like