Skip to contentSkip to conversation

A question about modifying the buffer under authenticated encryption

DISCUSSION Mikulas Patocka 3 participants 6 messages Feb 6, 2024 – Feb 8, 2024

Subsystems (2)
lore
Share & tools
lore

Mikulas Patocka

author maintainer
#0 lore raw

Hi

I'm trying to fix some problems in dm-crypt that it may report authentication failures when the user reads data with O_DIRECT and modifies the read buffer while it is being read.

I'd like to ask you:

1. If the authenticated encryption encrypts a message, reading from buffer1 and writing to buffer2 - and buffer1 changes while reading from it - is it possible that it generates invalid authentication tag?

2. If the authenticated encryption decrypts a message, reading from buffer1 and writing to buffer2 - and buffer2 changes while writing to it - is is possible that it reports authentication tag mismatch?

Mikulas

#1 lore raw
Quoted 8 lines · Mikulas Patocka

Hi

I'm trying to fix some problems in dm-crypt that it may report authentication failures when the user reads data with O_DIRECT and modifies the read buffer while it is being read.

I'd like to ask you:

Quoted 8 lines

1. If the authenticated encryption encrypts a message, reading from buffer1 and writing to buffer2 - and buffer1 changes while reading from it - is it possible that it generates invalid authentication tag?

2. If the authenticated encryption decrypts a message, reading from buffer1 and writing to buffer2 - and buffer2 changes while writing to it - is is possible that it reports authentication tag mismatch?

Yes, both scenarios are possible. But it depends on the AEAD algorithm and how it happens to be implemented, and on whether the data overlaps or not.

This is very much a "don't do that" sort of thing.

- Eric

author maintainer
#2 lore raw
Quoted 18 lines · Eric Biggers
Quoted 8 lines · Mikulas Patocka

Hi

I'm trying to fix some problems in dm-crypt that it may report authentication failures when the user reads data with O_DIRECT and modifies the read buffer while it is being read.

I'd like to ask you:

Quoted 8 lines

1. If the authenticated encryption encrypts a message, reading from buffer1 and writing to buffer2 - and buffer1 changes while reading from it - is it possible that it generates invalid authentication tag?

2. If the authenticated encryption decrypts a message, reading from buffer1 and writing to buffer2 - and buffer2 changes while writing to it - is is possible that it reports authentication tag mismatch?

Quoted 6 lines

Yes, both scenarios are possible. But it depends on the AEAD algorithm and how it happens to be implemented, and on whether the data overlaps or not.

This is very much a "don't do that" sort of thing.

- Eric

I see. So I will copy the data to a kernel buffer before encryption or decryption.

I assume that authenticated encryption or decryption using the same buffer as a source and as a destination should be ok. Right?

Mikulas

maintainer
#3 lore raw
Quoted 3 lines · Mikulas Patocka

I assume that authenticated encryption or decryption using the same buffer as a source and as a destination should be ok. Right?

Yes, in-place encryption and decryption is OK.

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#4 lore raw
In reply to Mikulas Patocka
Quoted 27 lines · Mikulas Patocka
Quoted 23 lines · Eric Biggers
Quoted 8 lines · Mikulas Patocka

Hi

I'm trying to fix some problems in dm-crypt that it may report authentication failures when the user reads data with O_DIRECT and modifies the read buffer while it is being read.

I'd like to ask you:

Quoted 8 lines

1. If the authenticated encryption encrypts a message, reading from buffer1 and writing to buffer2 - and buffer1 changes while reading from it - is it possible that it generates invalid authentication tag?

2. If the authenticated encryption decrypts a message, reading from buffer1 and writing to buffer2 - and buffer2 changes while writing to it - is is possible that it reports authentication tag mismatch?

Yes, both scenarios are possible. But it depends on the AEAD algorithm and how it happens to be implemented, and on whether the data overlaps or not.

This is very much a "don't do that" sort of thing.

Quoted 8 lines
Quoted 1 line

- Eric

I see. So I will copy the data to a kernel buffer before encryption or decryption.

I assume that authenticated encryption or decryption using the same buffer as a source and as a destination should be ok. Right?

The crypto_aead API allows the source and destination to overlap, yes.

- Eric

maintainer
#5 lore raw
Quoted 2 lines · Eric Biggers

The crypto_aead API allows the source and destination to overlap, yes.

I would prefer to call it in-place rather than overlapping, because the following is certainly not supported:

	encrypt(src: A, dst: A + 16, len: 160)

Just in case someone gets any funny ideas about the API :)

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt