Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FS#3494 - piped dd > 4096 will occasionally truncate on multi-core systems. Upstream suggests iflag=fullblock #8535

Closed
openwrt-bot opened this issue Dec 8, 2020 · 0 comments
Labels

Comments

@openwrt-bot
Copy link

johnth:

Found on mikrotik hap ac2 (currently an open PR), where radio calibration data will occasionally be truncated, showing as an incorrect wifi phy macaddr
#3037 (comment)

Piped dd for this device introduced with 7557e7f for caldata_from_file, caldata_sysfsload_from_file

Upstream busybox suggests using the iflag=fullblock https://git.busybox.net/busybox/commit/coreutils/dd.c?id=77a6678c427db5ea15d6d0005a579f441277df06
http://lists.busybox.net/pipermail/busybox/2020-November/088320.html
http://lists.busybox.net/pipermail/busybox/2020-November/088326.html

This worked as expected in a test of 1000 tries:

dd if=/sys/firmware/mikrotik/hard_config/wlan_data/data_0 iflag=skip_bytes,fullblock bs=$((0x2f20)) skip=0 count=1 2>/dev/null | sha256sum

Reproduce:

test_caldata_extract() { local counter local count_good local count_bad local result local result_latest local dd_bs
dd_bs=$((0x2f20))

dd if=/dev/urandom of=/tmp/wlan_data_0 bs=1M count=1
result=$(cat /tmp/wlan_data_0 | \
dd iflag=skip_bytes bs=$dd_bs skip=0 count=1 2>/dev/null | wc -c)
while [ ! $result -eq $dd_bs ]; do
echo "bad initial result"
result=$(cat /tmp/wlan_data_0 | \
dd iflag=skip_bytes bs=$dd_bs skip=0 count=1 2>/dev/null | wc -c)
done

counter=0
count_good=0
count_bad=0
echo "initial run $counter $result"

while true; do
counter=$(( counter + 1 ))
result_latest=$(cat /tmp/wlan_data_0 | \
dd iflag=skip_bytes bs=$((0x2f20)) skip=0 count=1 2>/dev/null | wc -c)
if [ "$result_latest" = "$result" ]; then
count_good=$(( count_good + 1 ))
#echo "run $counter okay"
else
count_bad=$(( count_bad + 1 ))
echo "run $counter bad $result_latest ($count_bad / $counter)"
#break
fi
done

}

test_caldata_extract

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant