Nuke out buffer overflow safety marker code, it duplicates similar code in

the malloc()/free() as well as having potential of softening the handling
in case error is detected down to a mere warning as compared to hard panic
in free().

Submitted by:	tsoome
Differential Revision:	https://reviews.freebsd.org/D18299
This commit is contained in:
Maxim Sobolev 2018-11-23 22:36:56 +00:00
parent 6d2e2df764
commit 6c81fe160c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=340857

View file

@ -86,7 +86,6 @@ static u_int bcache_rablks;
((bc)->bcache_ctl[BHASH((bc), (blkno))].bc_blkno != (blkno))
#define BCACHE_READAHEAD 256
#define BCACHE_MINREADAHEAD 32
#define BCACHE_MARKER 0xdeadbeef
static void bcache_invalidate(struct bcache *bc, daddr_t blkno);
static void bcache_insert(struct bcache *bc, daddr_t blkno);
@ -123,7 +122,6 @@ bcache_allocate(void)
u_int i;
struct bcache *bc = malloc(sizeof (struct bcache));
int disks = bcache_numdev;
uint32_t *marker;
if (disks == 0)
disks = 1; /* safe guard */
@ -142,8 +140,7 @@ bcache_allocate(void)
bc->bcache_nblks = bcache_total_nblks >> i;
bcache_unit_nblks = bc->bcache_nblks;
bc->bcache_data = malloc(bc->bcache_nblks * bcache_blksize +
sizeof(uint32_t));
bc->bcache_data = malloc(bc->bcache_nblks * bcache_blksize);
if (bc->bcache_data == NULL) {
/* dont error out yet. fall back to 32 blocks and try again */
bc->bcache_nblks = 32;
@ -158,9 +155,6 @@ bcache_allocate(void)
errno = ENOMEM;
return (NULL);
}
/* Insert cache end marker. */
marker = (uint32_t *)(bc->bcache_data + bc->bcache_nblks * bcache_blksize);
*marker = BCACHE_MARKER;
/* Flush the cache */
for (i = 0; i < bc->bcache_nblks; i++) {
@ -222,15 +216,12 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size,
int result;
daddr_t p_blk;
caddr_t p_buf;
uint32_t *marker;
if (bc == NULL) {
errno = ENODEV;
return (-1);
}
marker = (uint32_t *)(bc->bcache_data + bc->bcache_nblks * bcache_blksize);
if (rsize != NULL)
*rsize = 0;
@ -350,12 +341,6 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size,
result = 0;
}
if (*marker != BCACHE_MARKER) {
printf("BUG: bcache corruption detected: nblks: %zu p_blk: %lu, "
"p_size: %zu, ra: %zu\n", bc->bcache_nblks,
(long unsigned)BHASH(bc, p_blk), p_size, ra);
}
done:
if ((result == 0) && (rsize != NULL))
*rsize = size;