Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/upstream-android-3.4' into linux…
Browse files Browse the repository at this point in the history
…-sunxi-3.4
  • Loading branch information
amery committed Jul 25, 2012
2 parents 5b47d67 + 700f392 commit 6fe7800
Show file tree
Hide file tree
Showing 255 changed files with 3,155 additions and 1,690 deletions.
131 changes: 46 additions & 85 deletions Documentation/device-mapper/verity.txt
Expand Up @@ -7,39 +7,39 @@ This target is read-only.

Construction Parameters
=======================
<version> <dev> <hash_dev> <hash_start>
<version> <dev> <hash_dev>
<data_block_size> <hash_block_size>
<num_data_blocks> <hash_start_block>
<algorithm> <digest> <salt>

<version>
This is the version number of the on-disk format.
This is the type of the on-disk hash format.

0 is the original format used in the Chromium OS.
The salt is appended when hashing, digests are stored continuously and
the rest of the block is padded with zeros.
The salt is appended when hashing, digests are stored continuously and
the rest of the block is padded with zeros.

1 is the current format that should be used for new devices.
The salt is prepended when hashing and each digest is
padded with zeros to the power of two.
The salt is prepended when hashing and each digest is
padded with zeros to the power of two.

<dev>
This is the device containing the data the integrity of which needs to be
This is the device containing data, the integrity of which needs to be
checked. It may be specified as a path, like /dev/sdaX, or a device number,
<major>:<minor>.

<hash_dev>
This is the device that that supplies the hash tree data. It may be
This is the device that supplies the hash tree data. It may be
specified similarly to the device path and may be the same device. If the
same device is used, the hash_start should be outside of the dm-verity
configured device size.
same device is used, the hash_start should be outside the configured
dm-verity device.

<data_block_size>
The block size on a data device. Each block corresponds to one digest on
the hash device.
The block size on a data device in bytes.
Each block corresponds to one digest on the hash device.

<hash_block_size>
The size of a hash block.
The size of a hash block in bytes.

<num_data_blocks>
The number of data blocks on the data device. Additional blocks are
Expand All @@ -65,28 +65,28 @@ Construction Parameters
Theory of operation
===================

dm-verity is meant to be setup as part of a verified boot path. This
dm-verity is meant to be set up as part of a verified boot path. This
may be anything ranging from a boot using tboot or trustedgrub to just
booting from a known-good device (like a USB drive or CD).

When a dm-verity device is configured, it is expected that the caller
has been authenticated in some way (cryptographic signatures, etc).
After instantiation, all hashes will be verified on-demand during
disk access. If they cannot be verified up to the root node of the
tree, the root hash, then the I/O will fail. This should identify
tree, the root hash, then the I/O will fail. This should detect
tampering with any data on the device and the hash data.

Cryptographic hashes are used to assert the integrity of the device on a
per-block basis. This allows for a lightweight hash computation on first read
into the page cache. Block hashes are stored linearly-aligned to the nearest
block the size of a page.
per-block basis. This allows for a lightweight hash computation on first read
into the page cache. Block hashes are stored linearly, aligned to the nearest
block size.

Hash Tree
---------

Each node in the tree is a cryptographic hash. If it is a leaf node, the hash
is of some block data on disk. If it is an intermediary node, then the hash is
of a number of child nodes.
of some data block on disk is calculated. If it is an intermediary node,
the hash of a number of child nodes is calculated.

Each entry in the tree is a collection of neighboring nodes that fit in one
block. The number is determined based on block_size and the size of the
Expand All @@ -110,85 +110,46 @@ alg = sha256, num_blocks = 32768, block_size = 4096
On-disk format
==============

Below is the recommended on-disk format. The verity kernel code does not
read the on-disk header. It only reads the hash blocks which directly
follow the header. It is expected that a user-space tool will verify the
integrity of the verity_header and then call dmsetup with the correct
parameters. Alternatively, the header can be omitted and the dmsetup
parameters can be passed via the kernel command-line in a rooted chain
of trust where the command-line is verified.
The verity kernel code does not read the verity metadata on-disk header.
It only reads the hash blocks which directly follow the header.
It is expected that a user-space tool will verify the integrity of the
verity header.

The on-disk format is especially useful in cases where the hash blocks
are on a separate partition. The magic number allows easy identification
of the partition contents. Alternatively, the hash blocks can be stored
in the same partition as the data to be verified. In such a configuration
the filesystem on the partition would be sized a little smaller than
the full-partition, leaving room for the hash blocks.

struct superblock {
uint8_t signature[8]
"verity\0\0";

uint8_t version;
1 - current format

uint8_t data_block_bits;
log2(data block size)

uint8_t hash_block_bits;
log2(hash block size)

uint8_t pad1[1];
zero padding

uint16_t salt_size;
big-endian salt size

uint8_t pad2[2];
zero padding

uint32_t data_blocks_hi;
big-endian high 32 bits of the 64-bit number of data blocks

uint32_t data_blocks_lo;
big-endian low 32 bits of the 64-bit number of data blocks

uint8_t algorithm[16];
cryptographic algorithm

uint8_t salt[384];
salt (the salt size is specified above)

uint8_t pad3[88];
zero padding to 512-byte boundary
}
Alternatively, the header can be omitted and the dmsetup parameters can
be passed via the kernel command-line in a rooted chain of trust where
the command-line is verified.

Directly following the header (and with sector number padded to the next hash
block boundary) are the hash blocks which are stored a depth at a time
(starting from the root), sorted in order of increasing index.

The full specification of kernel parameters and on-disk metadata format
is available at the cryptsetup project's wiki page
http://code.google.com/p/cryptsetup/wiki/DMVerity

Status
======
V (for Valid) is returned if every check performed so far was valid.
If any check failed, C (for Corruption) is returned.

Example
=======

Setup a device:
dmsetup create vroot --table \
"0 2097152 "\
"verity 1 /dev/sda1 /dev/sda2 4096 4096 2097152 1 "\
Set up a device:
# dmsetup create vroot --readonly --table \
"0 2097152 verity 1 /dev/sda1 /dev/sda2 4096 4096 262144 1 sha256 "\
"4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 "\
"1234000000000000000000000000000000000000000000000000000000000000"

A command line tool veritysetup is available to compute or verify
the hash tree or activate the kernel driver. This is available from
the LVM2 upstream repository and may be supplied as a package called
device-mapper-verity-tools:
git://sources.redhat.com/git/lvm2
http://sourceware.org/git/?p=lvm2.git
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/verity?cvsroot=lvm2

veritysetup -a vroot /dev/sda1 /dev/sda2 \
4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076
the hash tree or activate the kernel device. This is available from
the cryptsetup upstream repository http://code.google.com/p/cryptsetup/
(as a libcryptsetup extension).

Create hash on the device:
# veritysetup format /dev/sda1 /dev/sda2
...
Root hash: 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076

Activate the device:
# veritysetup create vroot /dev/sda1 /dev/sda2 \
4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076
6 changes: 6 additions & 0 deletions Documentation/stable_kernel_rules.txt
Expand Up @@ -12,6 +12,12 @@ Rules on what kind of patches are accepted, and which ones are not, into the
marked CONFIG_BROKEN), an oops, a hang, data corruption, a real
security issue, or some "oh, that's not good" issue. In short, something
critical.
- Serious issues as reported by a user of a distribution kernel may also
be considered if they fix a notable performance or interactivity issue.
As these fixes are not as obvious and have a higher risk of a subtle
regression they should only be submitted by a distribution kernel
maintainer and include an addendum linking to a bugzilla entry if it
exists and additional information on the user-visible impact.
- New device IDs and quirks are also accepted.
- No "theoretical race condition" issues, unless an explanation of how the
race can be exploited is also provided.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
@@ -1,6 +1,6 @@
VERSION = 3
PATCHLEVEL = 4
SUBLEVEL = 4
SUBLEVEL = 5
EXTRAVERSION =
NAME = Saber-toothed Squirrel

Expand Down
67 changes: 62 additions & 5 deletions arch/arm/common/fiq_debugger.c
Expand Up @@ -81,6 +81,10 @@ struct fiq_debugger_state {
atomic_t unhandled_fiq_count;
bool in_fiq;

struct work_struct work;
spinlock_t work_lock;
char work_cmd[DEBUG_MAX];

#ifdef CONFIG_FIQ_DEBUGGER_CONSOLE
struct console console;
struct tty_struct *tty;
Expand Down Expand Up @@ -557,6 +561,53 @@ static void do_kgdb(struct fiq_debugger_state *state)
}
#endif

static void debug_schedule_work(struct fiq_debugger_state *state, char *cmd)
{
unsigned long flags;

spin_lock_irqsave(&state->work_lock, flags);
if (state->work_cmd[0] != '\0') {
debug_printf(state, "work command processor busy\n");
spin_unlock_irqrestore(&state->work_lock, flags);
return;
}

strlcpy(state->work_cmd, cmd, sizeof(state->work_cmd));
spin_unlock_irqrestore(&state->work_lock, flags);

schedule_work(&state->work);
}

static void debug_work(struct work_struct *work)
{
struct fiq_debugger_state *state;
char work_cmd[DEBUG_MAX];
char *cmd;
unsigned long flags;

state = container_of(work, struct fiq_debugger_state, work);

spin_lock_irqsave(&state->work_lock, flags);

strlcpy(work_cmd, state->work_cmd, sizeof(work_cmd));
state->work_cmd[0] = '\0';

spin_unlock_irqrestore(&state->work_lock, flags);

cmd = work_cmd;
if (!strncmp(cmd, "reboot", 6)) {
cmd += 6;
while (*cmd == ' ')
cmd++;
if (cmd != '\0')
kernel_restart(cmd);
else
kernel_restart(NULL);
} else {
debug_printf(state, "unknown work command '%s'\n", work_cmd);
}
}

/* This function CANNOT be called in FIQ context */
static void debug_irq_exec(struct fiq_debugger_state *state, char *cmd)
{
Expand All @@ -570,6 +621,8 @@ static void debug_irq_exec(struct fiq_debugger_state *state, char *cmd)
if (!strcmp(cmd, "kgdb"))
do_kgdb(state);
#endif
if (!strncmp(cmd, "reboot", 6))
debug_schedule_work(state, cmd);
}

static void debug_help(struct fiq_debugger_state *state)
Expand All @@ -579,7 +632,8 @@ static void debug_help(struct fiq_debugger_state *state)
" regs Register dump\n"
" allregs Extended Register dump\n"
" bt Stack trace\n"
" reboot Reboot\n"
" reboot [<c>] Reboot with command <c>\n"
" reset [<c>] Hard reset with command <c>\n"
" irqs Interupt status\n"
" kmsg Kernel log\n"
" version Kernel version\n");
Expand Down Expand Up @@ -630,16 +684,16 @@ static bool debug_fiq_exec(struct fiq_debugger_state *state,
dump_allregs(state, regs);
} else if (!strcmp(cmd, "bt")) {
dump_stacktrace(state, (struct pt_regs *)regs, 100, svc_sp);
} else if (!strncmp(cmd, "reboot", 6)) {
cmd += 6;
} else if (!strncmp(cmd, "reset", 5)) {
cmd += 5;
while (*cmd == ' ')
cmd++;
if (*cmd) {
char tmp_cmd[32];
strlcpy(tmp_cmd, cmd, sizeof(tmp_cmd));
kernel_restart(tmp_cmd);
machine_restart(tmp_cmd);
} else {
kernel_restart(NULL);
machine_restart(NULL);
}
} else if (!strcmp(cmd, "irqs")) {
dump_irqs(state);
Expand Down Expand Up @@ -1189,6 +1243,9 @@ static int fiq_debugger_probe(struct platform_device *pdev)
state->signal_irq = platform_get_irq_byname(pdev, "signal");
state->wakeup_irq = platform_get_irq_byname(pdev, "wakeup");

INIT_WORK(&state->work, debug_work);
spin_lock_init(&state->work_lock);

platform_set_drvdata(pdev, state);

spin_lock_init(&state->sleep_timer_lock);
Expand Down
17 changes: 9 additions & 8 deletions arch/arm/kernel/ftrace.c
Expand Up @@ -194,19 +194,20 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
old = *parent;
*parent = return_hooker;

err = ftrace_push_return_trace(old, self_addr, &trace.depth,
frame_pointer);
if (err == -EBUSY) {
*parent = old;
return;
}

trace.func = self_addr;
trace.depth = current->curr_ret_stack + 1;

/* Only trace if the calling function expects to */
if (!ftrace_graph_entry(&trace)) {
current->curr_ret_stack--;
*parent = old;
return;
}

err = ftrace_push_return_trace(old, self_addr, &trace.depth,
frame_pointer);
if (err == -EBUSY) {
*parent = old;
return;
}
}

Expand Down
1 change: 1 addition & 0 deletions arch/arm/mach-dove/include/mach/bridge-regs.h
Expand Up @@ -50,5 +50,6 @@
#define POWER_MANAGEMENT (BRIDGE_VIRT_BASE | 0x011c)

#define TIMER_VIRT_BASE (BRIDGE_VIRT_BASE | 0x0300)
#define TIMER_PHYS_BASE (BRIDGE_PHYS_BASE | 0x0300)

#endif
1 change: 1 addition & 0 deletions arch/arm/mach-dove/include/mach/dove.h
Expand Up @@ -78,6 +78,7 @@

/* North-South Bridge */
#define BRIDGE_VIRT_BASE (DOVE_SB_REGS_VIRT_BASE | 0x20000)
#define BRIDGE_PHYS_BASE (DOVE_SB_REGS_PHYS_BASE | 0x20000)

/* Cryptographic Engine */
#define DOVE_CRYPT_PHYS_BASE (DOVE_SB_REGS_PHYS_BASE | 0x30000)
Expand Down
1 change: 1 addition & 0 deletions arch/arm/mach-kirkwood/include/mach/bridge-regs.h
Expand Up @@ -38,6 +38,7 @@
#define IRQ_MASK_HIGH_OFF 0x0014

#define TIMER_VIRT_BASE (BRIDGE_VIRT_BASE | 0x0300)
#define TIMER_PHYS_BASE (BRIDGE_PHYS_BASE | 0x0300)

#define L2_CONFIG_REG (BRIDGE_VIRT_BASE | 0x0128)
#define L2_WRITETHROUGH 0x00000010
Expand Down
1 change: 1 addition & 0 deletions arch/arm/mach-kirkwood/include/mach/kirkwood.h
Expand Up @@ -80,6 +80,7 @@
#define UART1_VIRT_BASE (DEV_BUS_VIRT_BASE | 0x2100)

#define BRIDGE_VIRT_BASE (KIRKWOOD_REGS_VIRT_BASE | 0x20000)
#define BRIDGE_PHYS_BASE (KIRKWOOD_REGS_PHYS_BASE | 0x20000)

#define CRYPTO_PHYS_BASE (KIRKWOOD_REGS_PHYS_BASE | 0x30000)

Expand Down

0 comments on commit 6fe7800

Please sign in to comment.