mirror of
https://github.com/versity/scoutfs.git
synced 2026-08-15 19:56:36 +00:00
scoutfs: Ensure padding in structs remains zeroed
Audit code for structs allocated on stack without initialization, or
using kmalloc() instead of kzalloc().
- avl.c: zero padding in avl_node on insert.
- btree.c: Verify item padding is zero, or WARN_ONCE.
- inode.c: scoutfs_inode contains scoutfs_timespecs, which have padding.
- net.c: zero pad in net header.
- net.h: scoutfs_net_addr has padding, zero it in scoutfs_addr_from_sin().
- xattr.c: scoutfs_xattr has padding, zero it.
- forest.c: item_root in forest_next_hint() appears to either be
assigned-to or unused, so no need to zero it.
- key.h: Ensure padding is zeroed in scoutfs_key_set_{zeros,ones}
Signed-off-by: Andy Grover <agrover@versity.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
* General Public License for more details.
|
||||
*/
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
#include "format.h"
|
||||
#include "avl.h"
|
||||
@@ -274,6 +275,7 @@ void scoutfs_avl_insert(struct scoutfs_avl_root *root,
|
||||
node->left = 0;
|
||||
node->right = 0;
|
||||
set_height(root, node);
|
||||
memset(node->__pad, 0, sizeof(node->__pad));
|
||||
|
||||
if (parent == NULL) {
|
||||
root->node = node_off(root, node);
|
||||
|
||||
@@ -1003,6 +1003,7 @@ static bool bad_avl_node_off(__le16 node_off, int nr)
|
||||
* - values don't overlap each other
|
||||
* - last_free_offset is in fact last free region
|
||||
* - call after leaf modification
|
||||
* - padding is zero
|
||||
*/
|
||||
static void verify_btree_block(struct super_block *sb,
|
||||
struct scoutfs_btree_block *bt, int level,
|
||||
@@ -1017,6 +1018,7 @@ static void verify_btree_block(struct super_block *sb,
|
||||
int end_off;
|
||||
int tot = 0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int nr;
|
||||
|
||||
if (bt->level != level) {
|
||||
@@ -1055,6 +1057,10 @@ static void verify_btree_block(struct super_block *sb,
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (j = 0; j < sizeof(item->__pad); j++) {
|
||||
WARN_ON_ONCE(item->__pad[j] != 0);
|
||||
}
|
||||
|
||||
if (scoutfs_key_compare(&item->key, start) < 0 ||
|
||||
scoutfs_key_compare(&item->key, end) > 0) {
|
||||
reason = "item key out of parent range";
|
||||
|
||||
@@ -719,10 +719,13 @@ static void store_inode(struct scoutfs_inode *cinode, struct inode *inode)
|
||||
cinode->rdev = cpu_to_le32(inode->i_rdev);
|
||||
cinode->atime.sec = cpu_to_le64(inode->i_atime.tv_sec);
|
||||
cinode->atime.nsec = cpu_to_le32(inode->i_atime.tv_nsec);
|
||||
memset(cinode->atime.__pad, 0, sizeof(cinode->atime.__pad));
|
||||
cinode->ctime.sec = cpu_to_le64(inode->i_ctime.tv_sec);
|
||||
cinode->ctime.nsec = cpu_to_le32(inode->i_ctime.tv_nsec);
|
||||
memset(cinode->ctime.__pad, 0, sizeof(cinode->ctime.__pad));
|
||||
cinode->mtime.sec = cpu_to_le64(inode->i_mtime.tv_sec);
|
||||
cinode->mtime.nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
|
||||
memset(cinode->mtime.__pad, 0, sizeof(cinode->mtime.__pad));
|
||||
|
||||
cinode->meta_seq = cpu_to_le64(scoutfs_inode_meta_seq(inode));
|
||||
cinode->data_seq = cpu_to_le64(scoutfs_inode_data_seq(inode));
|
||||
|
||||
@@ -78,6 +78,7 @@ static inline void scoutfs_key_set_zeros(struct scoutfs_key *key)
|
||||
key->_sk_second = 0;
|
||||
key->_sk_third = 0;
|
||||
key->_sk_fourth = 0;
|
||||
memset(key->__pad, 0, sizeof(key->__pad));
|
||||
}
|
||||
|
||||
static inline bool scoutfs_key_is_zeros(struct scoutfs_key *key)
|
||||
@@ -104,6 +105,7 @@ static inline void scoutfs_key_set_ones(struct scoutfs_key *key)
|
||||
key->_sk_second = cpu_to_le64(U64_MAX);
|
||||
key->_sk_third = cpu_to_le64(U64_MAX);
|
||||
key->_sk_fourth = U8_MAX;
|
||||
memset(key->__pad, 0, sizeof(key->__pad));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -369,6 +369,7 @@ static int submit_send(struct super_block *sb,
|
||||
msend->nh.cmd = cmd;
|
||||
msend->nh.flags = flags;
|
||||
msend->nh.error = net_err;
|
||||
memset(msend->nh.__pad, 0, sizeof(msend->nh.__pad));
|
||||
msend->nh.data_len = cpu_to_le16(data_len);
|
||||
if (data_len)
|
||||
memcpy(msend->nh.data, data, data_len);
|
||||
|
||||
@@ -102,6 +102,7 @@ static inline void scoutfs_addr_from_sin(struct scoutfs_inet_addr *addr,
|
||||
{
|
||||
addr->addr = be32_to_le32(sin->sin_addr.s_addr);
|
||||
addr->port = be16_to_le16(sin->sin_port);
|
||||
memset(addr->__pad, 0, sizeof(addr->__pad));
|
||||
}
|
||||
|
||||
struct scoutfs_net_connection *
|
||||
|
||||
@@ -573,6 +573,7 @@ static int scoutfs_xattr_set(struct dentry *dentry, const char *name,
|
||||
id = si->next_xattr_id++;
|
||||
xat->name_len = name_len;
|
||||
xat->val_len = cpu_to_le16(size);
|
||||
memset(xat->__pad, 0, sizeof(xat->__pad));
|
||||
memcpy(xat->name, name, name_len);
|
||||
memcpy(&xat->name[xat->name_len], value, size);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user