[PATCH] CIPSO: Fix unaligned memory access in cipso_v4_gentag_hdr

Seergey Nazarov s-nazarov at yandex.ru
Fri Mar 5 07:28:25 UTC 2021


В Чт, 04/03/2021 в 22:17 +0100, Ondrej Mosnacek пишет:
> On Thu, Mar 4, 2021 at 10:09 PM Seergey Nazarov <s-nazarov at yandex.ru>
> wrote:
> > We need to use put_unaligned when writing 32-bit DOI value
> > in cipso_v4_gentag_hdr to avoid unaligned memory access.
> > 
> > Signed-off-by: Sergey Nazarov <s-nazarov at yandex.ru>
> > ---
> >  net/ipv4/cipso_ipv4.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
> > index 471d33a..28dfe40 100644
> > --- a/net/ipv4/cipso_ipv4.c
> > +++ b/net/ipv4/cipso_ipv4.c
> > @@ -1162,7 +1162,7 @@ static void cipso_v4_gentag_hdr(const struct
> > cipso_v4_doi *doi_def,
> >  {
> >         buf[0] = IPOPT_CIPSO;
> >         buf[1] = CIPSO_V4_HDR_LEN + len;
> > -       *(__be32 *)&buf[2] = htonl(doi_def->doi);
> > +       put_unaligned_be32(doi_def->doi, (__be32 *)&buf[2]);
> 
> I think you can now also drop the cast, since put_unaligned_be32()
> expects a void *.
> 
> >  }
> > 
> >  /**
> > --
> > 1.8.3.1
> > 
> > 
> 
> 
You are right, thanks!



More information about the Linux-security-module-archive mailing list