Content-Type: multipart/mixed; boundary="===============1595582237206110036==" MIME-Version: 1.0 From: Herbert Xu To: kbuild-all@lists.01.org Subject: Re: security/integrity/ima/ima_crypto.c:575:12: warning: stack frame size of 1152 bytes in function 'ima_calc_field_array_hash_tfm' Date: Fri, 19 Jun 2020 14:13:06 +1000 Message-ID: <20200619041306.GA22098@gondor.apana.org.au> In-Reply-To: <932f46e1-3ea9-e0cd-218a-db163c146a0e@intel.com> List-Id: --===============1595582237206110036== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On Fri, Jun 19, 2020 at 10:43:22AM +0800, Rong Chen wrote: > = > Could you take a look at this warning? Roberto mentioned you in previous > report: > https://lore.kernel.org/linux-integrity/9dbec9465bda4f8995a42593eb0db010(= a)huawei.com/ Well having a shash descriptor on the stack is always pushing the envelope. Doing it when you put another 256-byte string is obviously not a good idea. The good thing is that the string isn't necessary, so how about: ---8<--- The function ima_calc_field_array_hash_tfm uses a stack descriptor for shash. As hashing requires a large amount of space this means that you shouldn't put any other large data on the stack@the same time, for example, you definitely shouldn't put a 256-byte string which you're going to hash on the stack. Luckily this string is mostly composed of zeroes so we could just use ZERO_PAGE instead. Reported-by: kbuild test robot Signed-off-by: Herbert Xu diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/i= ma_crypto.c index 220b14920c37..0a925d1a1bf7 100644 --- a/security/integrity/ima/ima_crypto.c +++ b/security/integrity/ima/ima_crypto.c @@ -11,6 +11,7 @@ */ = #include +#include #include #include #include @@ -605,11 +606,11 @@ static int ima_calc_field_array_hash_tfm(struct ima_f= ield_data *field_data, return rc; = for (i =3D 0; i < num_fields; i++) { - u8 buffer[IMA_EVENT_NAME_LEN_MAX + 1] =3D { 0 }; u8 *data_to_hash =3D field_data[i].data; u32 datalen =3D field_data[i].len; u32 datalen_to_hash =3D !ima_canonical_fmt ? datalen : cpu_to_le32(datalen); + u32 padlen =3D 0; = if (strcmp(td->name, IMA_TEMPLATE_IMA_NAME) !=3D 0) { rc =3D crypto_shash_update(shash, @@ -617,14 +618,21 @@ static int ima_calc_field_array_hash_tfm(struct ima_f= ield_data *field_data, sizeof(datalen_to_hash)); if (rc) break; - } else if (strcmp(td->fields[i]->field_id, "n") =3D=3D 0) { - memcpy(buffer, data_to_hash, datalen); - data_to_hash =3D buffer; - datalen =3D IMA_EVENT_NAME_LEN_MAX + 1; - } + } else if (strcmp(td->fields[i]->field_id, "n") =3D=3D 0 && + datalen < IMA_EVENT_NAME_LEN_MAX + 1) + padlen =3D IMA_EVENT_NAME_LEN_MAX + 1 - datalen; + rc =3D crypto_shash_update(shash, data_to_hash, datalen); if (rc) break; + + if (padlen) { + const u8 *zero =3D page_address(ZERO_PAGE(0)); + + rc =3D crypto_shash_update(shash, zero, padlen); + if (rc) + break; + } } = if (!rc) -- = Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt --===============1595582237206110036==--