]> git.ipfire.org Git - ipfire-2.x.git/blame - src/patches/suse-2.6.27.39/patches.fixes/ocfs2-Check-xattr-block-signatures-properly.patch
Imported linux-2.6.27.39 suse/xen patches.
[ipfire-2.x.git] / src / patches / suse-2.6.27.39 / patches.fixes / ocfs2-Check-xattr-block-signatures-properly.patch
CommitLineData
2cb7cef9
BS
1From: Joel Becker <joel.becker@oracle.com>
2Date: Mon, 20 Oct 2008 18:20:43 -0700
3Subject: ocfs2: Check xattr block signatures properly.
4
5The xattr.c code is currently memcmp()ing naking buffer pointers.
6Create the OCFS2_IS_VALID_XATTR_BLOCK() macro to match its peers and use
7that.
8
9In addition, failed signature checks were returning -EFAULT, which is
10completely wrong. Return -EIO.
11
12Signed-off-by: Joel Becker <joel.becker@oracle.com>
13Signed-off-by: Mark Fasheh <mfasheh@suse.com>
14---
15 fs/ocfs2/ocfs2.h | 3 +++
16 fs/ocfs2/xattr.c | 38 ++++++++++++++++----------------------
17 2 files changed, 19 insertions(+), 22 deletions(-)
18
19Index: 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); \
25 } while (0)
26
27+#define OCFS2_IS_VALID_XATTR_BLOCK(ptr) \
28+ (!strcmp((ptr)->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE))
29+
30 static inline unsigned long ino_from_blkno(struct super_block *sb,
31 u64 blkno)
32 {
33Index: 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
38 mlog_errno(ret);
39 return ret;
40 }
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))) {
44- ret = -EFAULT;
45- goto cleanup;
46- }
47
48 xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
49+ if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) {
50+ ret = -EIO;
51+ goto cleanup;
52+ }
53
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
57 mlog_errno(ret);
58 return ret;
59 }
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))) {
63- ret = -EFAULT;
64+
65+ xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
66+ if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) {
67+ ret = -EIO;
68 goto cleanup;
69 }
70
71 xs->xattr_bh = blk_bh;
72- xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
73
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
77 goto out;
78 }
79
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))) {
83- ret = -EFAULT;
84+ xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
85+ if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) {
86+ ret = -EIO;
87 goto out;
88 }
89
90@@ -1540,7 +1536,6 @@ static int ocfs2_xattr_free_block(struct
91 goto out;
92 }
93
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
99 mlog_errno(ret);
100 return ret;
101 }
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))) {
105- ret = -EFAULT;
106- goto cleanup;
107+
108+ xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
109+ if (!OCFS2_IS_VALID_XATTR_BLOCK(xb)) {
110+ ret = -EIO;
111+ goto cleanup;
112 }
113
114 xs->xattr_bh = blk_bh;
115- xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
116
117 if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) {
118 xs->header = &xb->xb_attrs.xb_header;