This is an archive of the discontinued LLVM Phabricator instance.

Improve UBSan documentation
ClosedPublic

Authored by DianeMeirowitz on Jul 27 2021, 12:38 PM.

Details

Summary

Add more checks, info on -fno-sanitize=..., and reference to 5/2021 UBSan Oracle blog.

Diff Detail

Event Timeline

DianeMeirowitz requested review of this revision.Jul 27 2021, 12:38 PM
DianeMeirowitz created this revision.
hctim accepted this revision.Jul 27 2021, 1:55 PM

LGTM with nits. Do you need me to submit this patch for you?

clang/docs/UndefinedBehaviorSanitizer.rst
15–17

nit: "Array subscript out of bounds, when the bounds can be statically determined"

17

nit: "Dereferencing misaligned or null pointers"

This revision is now accepted and ready to land.Jul 27 2021, 1:55 PM

Mitch,

Thank you for reviewing my patch.

I don't agree with the phrasing : "Array subscript out of bounds, when the bounds can be statically determined". It is long, and I think it may confuse people who don't read language standards and also as far as I know, neither C nor C++ has a true dynamic array type. Dynamic arrays are declared as pointers, not arrays. So I suggest just keeping my original simple phrasing "Array subscript out of bounds". But if you feel strongly about this, go ahead.

I agree with the second nit, "Dereferencing misaligned or null pointers", since these pointers are fine until they are dereferenced, of course.

Yes, if you are willing to submit the patch, please do. And thank you!

Diane

On 7/27/21, 4:55 PM, "Mitch Phillips via Phabricator" <reviews@reviews.llvm.org> wrote:

hctim accepted this revision.
hctim added a comment.
This revision is now accepted and ready to land.

LGTM with nits. Do you need me to submit this patch for you?



================
Comment at: clang/docs/UndefinedBehaviorSanitizer.rst:15

-* Using misaligned or null pointer
+* Array subscript out of bounds
+* Bitwise shifts that are out of bounds for their data type
----------------
nit: "Array subscript out of bounds, when the bounds can be statically determined"


================
Comment at: clang/docs/UndefinedBehaviorSanitizer.rst:17
+* Bitwise shifts that are out of bounds for their data type
+* Misaligned or null pointer
 * Signed integer overflow
----------------
nit: "Dereferencing misaligned or null pointers"


CHANGES SINCE LAST ACTION
  https://urldefense.com/v3/__https://reviews.llvm.org/D106908/new/__;!!ACWV5N9M2RV99hQ!fAT1f8xnLfUbRHWvjZ5u6KH3mZasWxxcgnq38vA1e9N4TyKUwqGrc4R8QLMDGrP0rzi1$ 

https://urldefense.com/v3/__https://reviews.llvm.org/D106908__;!!ACWV5N9M2RV99hQ!fAT1f8xnLfUbRHWvjZ5u6KH3mZasWxxcgnq38vA1e9N4TyKUwqGrc4R8QLMDGmhc9eVw$

Hi Mitch,

Do I need to do anything further with this, like upload a revised patch?

Diane

On 7/28/21, 10:14 AM, "Diane Meirowitz via Phabricator" <reviews@reviews.llvm.org> wrote:

DianeMeirowitz added subscribers: eugenis, jkorous, kuhnel.
DianeMeirowitz added a comment.

Mitch,

Thank you for reviewing my patch.

I don't agree with the phrasing : "Array subscript out of bounds, when the bounds can be statically determined". It is long, and I think it may confuse people who don't read language standards and also as far as I know, neither C nor C++ has a true dynamic array type. Dynamic arrays are declared as pointers, not arrays. So I suggest just keeping my original simple phrasing "Array subscript out of bounds". But if you feel strongly about this, go ahead.

I agree with the second nit, "Dereferencing misaligned or null pointers", since these pointers are fine until they are dereferenced, of course.

Yes, if you are willing to submit the patch, please do. And thank you!

Diane
hctim added a comment.Aug 2 2021, 2:55 PM

I don't agree with the phrasing : "Array subscript out of bounds, when the bounds can be statically determined". It is long, and I think it may confuse people who don't read language standards and also as far as I know, neither C nor C++ has a true dynamic array type. Dynamic arrays are declared as pointers, not arrays. So I suggest just keeping my original simple phrasing "Array subscript out of bounds". But if you feel strongly about this, go ahead.

Indirection can kill the bounds tracking, so we normally add the caveat that "the bounds can be statically determined". For example, this simple case escapes ubsan-bounds (but not asan):

int f(int y[]) {
  return y[1];
}

int main() {
  int x[1];
  return f(x);
}

I'll submit with the nit.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2021, 3:10 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Mitch,

OK and thanks for submitting it!

Diane

On 8/2/21, 5:55 PM, "Mitch Phillips via Phabricator" <reviews@reviews.llvm.org> wrote:

hctim added a comment.

In D106908#2910131 <https://urldefense.com/v3/__https://reviews.llvm.org/D106908*2910131__;Iw!!ACWV5N9M2RV99hQ!ezsHkymW9n_oArVw48GURjA0PCnyK2zxkbZU2B9adp3WEpn3KvcVau7Y0fo6bxKxWNDu$ >, @DianeMeirowitz wrote:

> I don't agree with the phrasing : "Array subscript out of bounds, when the bounds can be statically determined". It is long, and I think it may confuse people who don't read language standards and also as far as I know, neither C nor C++ has a true dynamic array type. Dynamic arrays are declared as pointers, not arrays. So I suggest just keeping my original simple phrasing "Array subscript out of bounds". But if you feel strongly about this, go ahead.

Indirection can kill the bounds tracking, so we normally add the caveat that "the bounds can be statically determined". For example, this simple case escapes ubsan-bounds (but not asan):

  int f(int y[]) {
    return y[1];
  }

  int main() {
    int x[1];
    return f(x);
  }

I'll submit with the nit.


CHANGES SINCE LAST ACTION
  https://urldefense.com/v3/__https://reviews.llvm.org/D106908/new/__;!!ACWV5N9M2RV99hQ!ezsHkymW9n_oArVw48GURjA0PCnyK2zxkbZU2B9adp3WEpn3KvcVau7Y0fo6b0vh3Zht$ 

https://urldefense.com/v3/__https://reviews.llvm.org/D106908__;!!ACWV5N9M2RV99hQ!ezsHkymW9n_oArVw48GURjA0PCnyK2zxkbZU2B9adp3WEpn3KvcVau7Y0fo6b5X0CPtC$