Yes, this can be done with JNI, see e.g. [1]. Additionally, by using
sun.misc.Unsafe [2], one can cause segfaults even from pure Java.
[1] https://www.cs.princeton.edu/~appel/papers/safejni.pdf
[2] http://www.inf.usi.ch/faculty/lanza/Downloads/ Mast2015a.pdf
If you have the energy, it'd be great to put some of this thinking
into a wiki page (https://ghc.haskell.org/trac/ghc/wiki/SafeHaskell )
and flesh out a first approximation of what IO API's cause issues. Is
it just Ptr not carrying bounds around with it? Maybe, but then we
need to secure how Ptr's can be created, which excludes FFI returning
Ptr's.