On Tue, Oct 30, 2012 at 5:59 PM, David Howells <dhowe...@redhat.com> wrote: > Kees Cook <keesc...@chromium.org> wrote: > >> This multiplication can push the cursor out of bounds. (n_data_dirents >> is unverified). >> ... >> Both of these cases of n_sections multiplications can wrap. >> Ultimately, you can end up with cursor close to zero, but n_sections >> being giant. > > Good points. I wonder if I should limit these to some low number, or just > check that they don't exceed header_size, which also needs checking as you > said.
I think header_size can be bounded by datalen? I didn't investigate that one very deeply. For the multiplications, I think you can just do a check before chkaddr: ctx->n_sections = pe->sections; if (datalen / ctx->n_sections > sizeof(*sec)) return -ELIBBAD; chkaddr(0, cursor, sizeof(*sec) * ctx->n_sections); Or extend chkaddr to do the check for you: chkaddr(0, cursor, sizeof(*sec), ctx->n_sections); with other callers just using "1" for the final argument. Either way, you won't have to choose arbitrary limits. -Kees -- Kees Cook Chrome OS Security -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/