1 From: Joel Becker <joel.becker@oracle.com>
2 Date: Mon, 20 Oct 2008 18:20:43 -0700
3 Subject: ocfs2: Check xattr block signatures properly.
5 The xattr.c code is currently memcmp()ing naking buffer pointers.
6 Create the OCFS2_IS_VALID_XATTR_BLOCK() macro to match its peers and use
9 In addition, failed signature checks were returning -EFAULT, which is
10 completely wrong. Return -EIO.
12 Signed-off-by: Joel Becker <joel.becker@oracle.com>
13 Signed-off-by: Mark Fasheh <mfasheh@suse.com>
15 fs/ocfs2/ocfs2.h | 3 +++
16 fs/ocfs2/xattr.c | 38 ++++++++++++++++----------------------
17 2 files changed, 19 insertions(+), 22 deletions(-)
19 Index: linux-2.6.27-ocfs2/fs/ocfs2/ocfs2.h
20 ===================================================================
21 --- linux-2.6.27-ocfs2.orig/fs/ocfs2/ocfs2.h
22 +++ linux-2.6.27-ocfs2/fs/ocfs2/ocfs2.h
23 @@ -473,6 +473,9 @@ static inline int ocfs2_uses_extended_sl
24 (____gd)->bg_signature); \
27 +#define OCFS2_IS_VALID_XATTR_BLOCK(ptr) \
28 + (!strcmp((ptr)->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE))
30 static inline unsigned long ino_from_blkno(struct super_block *sb,
33 Index: linux-2.6.27-ocfs2/fs/ocfs2/xattr.c
34 ===================================================================
35 --- linux-2.6.27-ocfs2.orig/fs/ocfs2/xattr.c
36 +++ linux-2.6.27-ocfs2/fs/ocfs2/xattr.c
37 @@ -555,14 +555,12 @@ static int ocfs2_xattr_block_list(struct
41 - /*Verify the signature of xattr block*/
42 - if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE,
43 - strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) {
48 xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
49 + if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) {
54 if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) {
55 struct ocfs2_xattr_header *header = &xb->xb_attrs.xb_header;
56 @@ -779,15 +777,14 @@ static int ocfs2_xattr_block_get(struct
60 - /*Verify the signature of xattr block*/
61 - if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE,
62 - strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) {
65 + xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
66 + if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) {
71 xs->xattr_bh = blk_bh;
72 - xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
74 if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) {
75 xs->header = &xb->xb_attrs.xb_header;
76 @@ -1527,10 +1524,9 @@ static int ocfs2_xattr_free_block(struct
80 - /*Verify the signature of xattr block*/
81 - if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE,
82 - strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) {
84 + xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
85 + if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) {
90 @@ -1540,7 +1536,6 @@ static int ocfs2_xattr_free_block(struct
94 - xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
95 blk = le64_to_cpu(xb->xb_blkno);
96 bit = le16_to_cpu(xb->xb_suballoc_bit);
97 bg_blkno = ocfs2_which_suballoc_group(blk, bit);
98 @@ -1784,15 +1779,14 @@ static int ocfs2_xattr_block_find(struct
102 - /*Verify the signature of xattr block*/
103 - if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE,
104 - strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) {
108 + xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
109 + if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) {
114 xs->xattr_bh = blk_bh;
115 - xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
117 if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) {
118 xs->header = &xb->xb_attrs.xb_header;