Skip to content

Commit

Permalink
[CRYPTO] api: Fix scatterwalk_sg_chain
Browse files Browse the repository at this point in the history
When I backed out of using the generic sg chaining (as it isn't currently
portable) and introduced scatterwalk_sg_chain/scatterwalk_sg_next I left
out the sg_is_last check in the latter.  This causes it to potentially
dereference beyond the end of the sg array.

As most uses of scatterwalk_sg_next are bound by an overall length, this
only affected the chaining code in authenc and eseqiv. Thanks to Patrick
McHardy for identifying this problem.

This patch also clears the "last" bit on the head of the chained list as
it's no longer last.  This also went missing in scatterwalk_sg_chain and
is present in sg_chain.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Herbert Xu committed May 1, 2008
1 parent 1616132 commit 8ec970d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/crypto/scatterwalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ static inline void scatterwalk_sg_chain(struct scatterlist *sg1, int num,
struct scatterlist *sg2)
{
sg_set_page(&sg1[num - 1], (void *)sg2, 0, 0);
sg1[num - 1].page_link &= ~0x02;
}

static inline struct scatterlist *scatterwalk_sg_next(struct scatterlist *sg)
{
if (sg_is_last(sg))
return NULL;

return (++sg)->length ? sg : (void *)sg_page(sg);
}

Expand Down

0 comments on commit 8ec970d

Please sign in to comment.