Revert "lzo: properly check for overruns"

This reverts commit ("lzo: properly check for overruns").

As analysed by Willem Pinckaers, this fix is still incomplete on
certain rare corner cases, and it is easier to restart from the
original code.

Reported-by: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
lzo: check for length overrun in variable length encoding.

This fix ensures that we never meet an integer overflow while adding
255 while parsing a variable length encoding. It works differently from
commit 206a81c ("lzo: properly check for overruns") because instead of
ensuring that we don't overrun the input, which is tricky to guarantee
due to many assumptions in the code, it simply checks that the cumulated
number of 255 read cannot overflow by bounding this number.

The MAX_255_COUNT is the maximum number of times we can add 255 to a base
count without overflowing an integer. The multiply will overflow when
multiplying 255 by more than MAXINT/255. The sum will overflow earlier
depending on the base count. Since the base count is taken from a u8
and a few bits, it is safe to assume that it will always be lower than
or equal to 2*255, thus we can always prevent any overflow by accepting
two less 255 steps.

This patch also reduces the CPU overhead and actually increases performance
by 1.1% compared to the initial code, while the previous fix costs 3.1%
(measured on x86_64).

The fix needs to be backported to all currently supported stable kernels.

Reported-by: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Documentation: lzo: document part of the encoding

Add a complete description of the LZO format as processed by the
decompressor. I have not found a public specification of this format
hence this analysis, which will be used to better understand the code.

Cc: Willem Pinckaers <willem@lekkertech.net>
Cc: "Don A. Bailey" <donb@securitymouse.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Config Restore as was with 5.9. nothing bad added.
msm: ipc_logging: remove internal details from header

Some internal details no longer need to be shared between modules, so
they can be moved to the main implementation file to avoid unnecessary
coupling in the future.

Change-Id: Ie8774f0c95f5ec6a56a95c57fea79032194eb05e
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: add client version support

If clients use custom serialization functions, then they may need to
define a version for deserialization support for log extraction.

Add client version support.

Change-Id: Id135f06d4142de39275b5d0caab88708d5496b5e
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: add locking hierarchy

Add locking hierarchy to allow identification of deadlocks by code
inspection.

Change-Id: I41cd479d72be7b2c729fbf09b5b89180c0a11191
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: enhance log-extraction support

One of the main goals of the IPC Logging is to allow extracting logs
from memory dumps.  The current implementation has the following
limitations:

  1) if logs are being dumped through debugfs at the time of the crash,
     it is not possible to extract logs that were already dumped

  2) it is not always possible to tell the difference between empty,
     partially full, and full log pages resulting in extraction
     complications

  3) if the system memory is not cleared between reboots, then the same
     log ID and log page may be extracted leading to duplicate log
     pages

Add additional debugfs read index, timestamps for log pages, and change
the read/write indices to easily differentiate between empty, partially
full, and full log pages.

CRs-Fixed: 670345
Change-Id: I695f6e0605f3755b868ede59851f5ca919f8fb0d
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: reset completion instead of reinitializing

init_completion() is being used to reinitialize the read completion
which will cause problems if complete_all() is ever used.

Use INIT_COMPLETION instead of init_completion() to reinitialize
the completion.

Change-Id: I33a78559d9debb6c90a039bd9f22f391c6c15f27
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
msm: ipc_logging: fix non-destructive read logic

When dumping logs through debugfs, a non-destructive read is performed
and after all data has been printed, the call waits on a completion for
new log data.  When that event is completed, the entire contents of the
logs are incorrectly printed.

Fix the read logic to correctly update the non-destructive read pointer
such that only the new data is printed to the logs.

CRs-Fixed: 681317
Change-Id: Ia12787b576b18b9f5174cefe91eb283979c286f7
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
ipc_logging: Validate the next page pointer

Validate the pointer returned from get_next_page function.

Change-Id: I32d7c0771d116186fffb206335993f6114e303f8
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
Fix last ipc_log_context_create in msm_serial_hs.c after https://github.com/neobuddy89/hammerhead/commit/18c260d3bf1bf5a7c7741abdb9c58f6b10219e4f