Module 6 · Lesson 104 of 108

Debugging and security scenarios

Explain how you would diagnose an embedded Linux failure, defend a service design, and use measurements to justify technical decisions in an interview.

  • Beginner to advanced
  • 9 min read
  • 18 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM for practice. The exercises use written scenarios and require no board.

Your place in the module
By the end you can 4 objectives
  • Choose evidence that distinguishes likely causes of hangs, crashes, memory growth, and failed updates.
  • Propose and verify least-privilege controls for a network-facing service.
  • Explain one subsystem guarantee and the limits of that guarantee.
  • Define a measurement and a verification step for a proposed fix.
Video coming soonDebugging and security scenarios
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Live coding and the why questions
  • A successful cross-build still needs an architecture and ABI check.
  • An epoll readiness notification still requires checking the result of the I/O call.
  • Atomic file replacement and durability after power loss require different operations.
01

Diagnose the failure before proposing a fix

4 min read

Coding is not the whole interview; this lesson covers debugging and security scenarios plus the deep dives.

A real constraint documented in core(5) gives you a useful interview opening. The kernel can send a dump to a handler instead of writing a file in the process's working directory. A device can therefore report a crash while the directory contains no core file. Say how you would check what the system actually collected before drawing a conclusion. The same reasoning applies when an interviewer says a device is “hung” or “bricked.” Ask which operation failed, when it last worked, and what independent evidence is available.

A hung service. Suppose a gateway still answers SSH but stops reporting sensor readings. Ask whether the whole gateway service is unresponsive or whether only publishing has stopped. Record the affected build, the unit state, recent journal entries, and the last completed operation. On a systemd installation, systemctl status gateway.service and journalctl -u gateway.service -b are reasonable first checks for a unit named gateway.service. Compare thread CPU activity over an interval. A busy thread makes a loop or repeated retries plausible. Low CPU makes a blocked dependency, lock, or idle event loop worth checking. Neither observation establishes the cause.

If a debugger attach is acceptable, collect all thread stacks and say that attaching can pause the process. A thread waiting in epoll_wait may be operating normally. If a request is pending, find out which thread should make it ready and whether that thread is progressing. A lock wait calls for evidence about the lock holder. A network wait calls for evidence about the peer and the timeout. Capture what you can before an approved restart, then check that a real sensor reading reaches its destination after recovery.

A crash. Record the terminating signal, deploy version, architecture, and recent inputs. Check /proc/sys/kernel/core_pattern to see whether the kernel is configured to write a file or invoke a handler. Check the service's dump limits, storage and access policy. Treat the dump as sensitive because it can contain memory such as credentials or customer data. Open a recovered dump with gdb /path/to/executable /path/to/core, substituting the deployed executable and the captured dump. Use the matching target libraries and debug symbols, and a debugger that supports the target architecture. In GDB, thread apply all bt full gives thread backtraces and available locals. Inspect the faulting frame and its callers. A fault in a copy routine tells you where execution failed. To explain why, trace the buffer's ownership and length back to the call site and verify your hypothesis with a targeted reproduction.

A memory leak. Ask how memory was measured and whether growth follows time, requests, or reconnects. Repeat a fixed workload with warm-up and idle periods. Track resident memory and compare /proc/PID/smaps samples, substituting the live process ID, to see which mappings account for growth. Rising RSS warrants investigation. Allocator retention, a warming cache, and a growing queue can all raise RSS. On a representative test build, use a heap profiler to compare live allocations after equal workload cycles. If retained allocations track reconnects, inspect their allocation stacks and the cleanup on that path. Verify that outstanding objects plateau across repeated cycles after the fix.

An OTA that bricked a device. Pause the rollout and compare affected units by board revision and image version. Ask what the serial console shows and identify the last stage with evidence of success. If Linux starts but telemetry never returns, inspect service startup, network configuration, and any persistent-data migration. If the kernel never starts, collect available bootloader logs and slot-selection state. For a design with A/B root filesystems, check which slot was selected, whether the trial boot was marked healthy, and why the fallback did or did not occur. Use the device's supported rollback or recovery procedure and preserve persistent data and evidence before any reflash. For prevention, verify that the previous image can still read shared data after a trial boot and test power loss at update state transitions on the target hardware.

First evidence by symptomSymptomFirstevidenceHangNo serviceprogressJournal andthreadactivityCrashProcessterminatedSignal anddump policyMemory growthRSS growsMappingtrends acrosscyclesFailed OTADeviceunavailableConsole andslot state
How the reported symptom guides the first evidence you collect
02

Justify the service's privileges

2 min read

For a security question, start with what the service must protect and what it must do. Consider a gateway that reads a local sensor and publishes over TLS. Its assets include device identity, telemetry integrity, and the ability to install trusted updates. Draw the paths from the sensor to the publisher, from the publisher to the broker, and from the update service to the boot storage. Mark where data changes owner or enters from another trust domain. Ask who controls each input, what access they already have, and what impact a failure could have. That gives you a threat model with assumptions you can state and revise during the interview.

Apply least privilege to each required operation. Run the publisher as a dedicated user. Give it access to the specific sensor interface it needs and to its own writable state. Keep write access to the update slots with the update service. If the publisher has no privileged operations, run it with no capabilities. Linux capabilities grant specific classes of privilege. For example, CAP_NET_BIND_SERVICE authorizes binding an Internet socket below the configured unprivileged port start. An ordinary outbound connection to a broker does not require it. Device access still depends on the relevant file permissions and any applicable device policy. In the interview, name the operation behind each requested grant and describe a test that removes the grant to verify the dependency.

For secrets handling, use individual device identities so you can revoke one without replacing every device's credential. Keep private keys out of firmware images, source control, command-line arguments, and logs. Restrict read access to the service that uses the key, or have it request signing from hardware that keeps the key non-exportable when the product supports that. Explain how fulfilment provisions the identity, how the service receives it, and how operators rotate or revoke it. Include the reconnect behaviour after rotation. A replacement credential that only works after an unscheduled reboot can become an availability problem.

Connect each control to evidence. Test that the publisher can read and transmit sensor data, that its user cannot write update storage, and that the broker rejects the revoked test identity. Name a residual risk. For example, a compromised publisher can still submit false telemetry using privileges it needs for its normal job. Broker authentication establishes which identity connected. Detecting false readings requires independent evidence about the readings themselves.

Gateway service accessGatewayPublisherSensor interfaceRead required dataBrokerPublish over TLSUpdate serviceUpdate slotsWrite verified imagesGatewayPublisherSensor interfaceRead required dataBrokerPublish over TLSUpdate serviceUpdate slotsWrite verified images
Publisher and update service have separate access requirements
03

Explain a subsystem guarantee and how you would test it

3 min read
Going deeperPersistence and delivery under interruption

SQLite WAL. If a write-heavy gateway reports a growing WAL file, ask about long-lived read transactions and checkpoint progress. A reader uses a snapshot defined by the last valid commit visible when its read transaction begins. WAL frames contain changed database pages, and a checkpoint copies eligible pages back into the database file. A reader holding an older snapshot can limit how far a checkpoint progresses and prevent the WAL from being reset while still in use. Compare checkpoint progress and active reader lifetimes, then end the suspect read transaction on a test system and compare again. A WAL file can remain allocated for reuse after checkpointing, so file size alone tells you little about current backlog.

MQTT QoS 2. Describe PUBLISH, PUBREC, PUBREL, and PUBCOMP for one sender-receiver exchange. The endpoints track the exchange using a packet identifier, and the ability to resume it after reconnect depends on retained session state. The protocol's exactly-once delivery guarantee applies to that MQTT exchange. If the subscriber performs an external action and crashes before recording the outcome, the protocol cannot establish whether that action happened. Give a command a durable application identifier. Explain how the receiver can reconcile the outcome or make retrying the command safe.

Going deeperDisplay, containers, and kernel observations

DRM atomic modesetting. A display configuration may change plane, CRTC, and connector state together. Explain that the driver validates the proposed state as a whole, including constraints such as supported formats, scaling, and bandwidth where applicable. A test-only atomic commit validates the proposal without applying it. If a real commit is accepted but the screen stays blank, distinguish commit completion from visible output. Check a completion event if one was requested, then investigate the selected connector, framebuffer contents, and display path.

Container runtimes. For a process that starts on the host but fails in a container, distinguish image and root filesystem preparation from process creation. An OCI runtime such as runc applies the supplied process and isolation configuration. Check the configured user, mounts, device access, namespaces, and cgroup limits against the operation that failed. A missing device node and an existing node denied by policy call for different checks. Describe the smallest configuration change that restores the required operation, then verify that unrelated devices remain inaccessible.

eBPF observability. To investigate sporadic latency, say which event you would measure. For scheduler delay, correlate a thread's wake-up with its next scheduling event and aggregate the interval into a histogram. Filter to the affected service. If you export individual events through a BPF ring buffer, account for reservation failures and measure tracing overhead. A quiet trace with dropped events is weak evidence. State which observation would move the investigation toward scheduling and which would send you back to application timing.

One MQTT QoS 2 exchangeSenderReceiverPUBLISHPUBRECPUBRELPUBCOMP1. Sender → ReceiverPUBLISH2. Receiver → SenderPUBREC3. Sender → ReceiverPUBREL4. Receiver → SenderPUBCOMP
The QoS 2 handshake between two MQTT peers
Going deeperPerformance and production failure answers

For an optimisation question, name the metric, the target board, and the workload. If the complaint is late telemetry, measure the tail of the sensor-to-publish latency distribution at a representative input rate. Measure elapsed time within each stage and time spent waiting between stages. If the queue before publish accounts for the delay, test one change under the same workload. Report latency alongside CPU use, memory, and dropped readings so the interviewer can judge the trade-off.

For a production failure story, use an incident you can substantiate. Give the timeline, the impact, the recovery action, and the evidence for the root cause. In a hypothetical OTA answer, an older binary failing to read a shared database after fallback suggests a migration incompatibility. To confirm it, reproduce the upgrade and fallback on a copy of the data, observe the earlier binary's failure, and repeat with a compatible migration. State what allowed the fault to reach devices, such as a test plan that exercised forward updates only. If the evidence supports only a hypothesis, say what observation is missing.

The next lesson, Behavioral questions and pitfalls, follows by looking at how you explain your decisions and your role when the interviewer asks about work you have done.

Key takeaways

  • A running PID can belong to a service that has stopped making progress.
  • A useful core backtrace depends on matching the deployed executable, libraries, and debug symbols.
  • A trial boot can succeed at the OS level while the product function fails.
  • MQTT QoS 2 does not make an external application action exactly-once.
Reflect
  1. Explain to a colleague, in two sentences: choose evidence that distinguishes likely causes of hangs, crashes, memory growth, and failed updates.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close