Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform validation before reading new data for FTrace header parser
According to OWASP 2021 top 10 list [1], injection attacks are the third most common type of cyber attack in 2021. When parsing a specific section in the binary Ftrace header, the parser needs to read the section size, then use this value as the limit to read the content of the section. One can take advantage of this by modifying the section sizes to go out of the trace size limit, thus gaining access into unrelated memory locations. This commit adds a security layer for the Ftrace header parser. It ensures that the parser will not go out of bound by comparing the expected different sections with the binary FTrace format and file size. [1] https://owasp.org/Top10/ Change-Id: I561c94838324b0c5da86401d7405081ef29affbe Signed-off-by: Hoang Thuan Pham <hoang.pham@calian.ca> Reviewed-on: https://git.eclipse.org/r/c/tracecompass.incubator/org.eclipse.tracecompass.incubator/+/191407 Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com> Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
- Loading branch information
1 parent
a734f67
commit e65e905
Showing
8 changed files
with
369 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../tracecompass/incubator/ftrace/core/tests/binary/security/BinaryFTraceFileParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Ericsson | ||
* | ||
* All rights reserved. This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 which | ||
* accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.tracecompass.incubator.ftrace.core.tests.binary.security; | ||
|
||
import java.io.IOException; | ||
|
||
import org.eclipse.tracecompass.incubator.ftrace.core.tests.shared.FTraceUtils; | ||
import org.eclipse.tracecompass.incubator.internal.ftrace.core.binary.parser.BinaryFTraceFileParser; | ||
import org.eclipse.tracecompass.testtraces.ftrace.FtraceTestTrace; | ||
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Perform various security tests for the BinaryFTraceFileParserImp | ||
* | ||
* @author Hoang Thuan Pham | ||
*/ | ||
public class BinaryFTraceFileParserTest { | ||
private static String injectedTraceHeaderPageSection; | ||
private static String injectedTraceCPU; | ||
|
||
/** | ||
* Initialize the paths to the trace files | ||
* | ||
* @throws IOException | ||
* If an error occurred while getting the trace paths | ||
*/ | ||
@BeforeClass | ||
public static void init() throws IOException { | ||
injectedTraceHeaderPageSection = FTraceUtils.getTraceAbsolutePath(FtraceTestTrace.TEST_2_6_BAD_HEADER_PAGE_SECTION_SIZE); | ||
injectedTraceCPU = FTraceUtils.getTraceAbsolutePath(FtraceTestTrace.TEST_2_6_BAD_CPU_SECTION_SIZE); | ||
} | ||
|
||
/** | ||
* A03 Injection | ||
*/ | ||
/** | ||
* Test parsing a trace injected with a bad Header Page section size | ||
* | ||
* @throws TmfTraceException | ||
* If the parser fails to parse the trace | ||
*/ | ||
@Test(expected = TmfTraceException.class) | ||
public void testBadHeaderPageSectionSize() throws TmfTraceException { | ||
BinaryFTraceFileParser.parse(injectedTraceHeaderPageSection); | ||
} | ||
|
||
/** | ||
* Test parsing a trace injected with a bad CPU section size | ||
* | ||
* @throws TmfTraceException | ||
* If the parser fails to parse the trace | ||
*/ | ||
@Test(expected = TmfTraceException.class) | ||
public void testBadCpuSectionSize() throws TmfTraceException { | ||
BinaryFTraceFileParser.parse(injectedTraceCPU); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.