From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15696 invoked by alias); 30 Sep 2013 08:55:12 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 15678 invoked by uid 89); 30 Sep 2013 08:55:11 -0000 Received: from sam.nabble.com (HELO sam.nabble.com) (216.139.236.26) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 30 Sep 2013 08:55:11 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=ham version=3.3.2 X-HELO: sam.nabble.com Received: from tom.nabble.com ([192.168.236.105]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1VQZFz-0000Z4-CR for ecos-discuss@ecos.sourceware.org; Mon, 30 Sep 2013 01:55:07 -0700 Date: Mon, 30 Sep 2013 08:55:00 -0000 From: Daniel Zebralla To: ecos-discuss@ecos.sourceware.org Message-ID: <1380531306664-245720.post@n7.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: [ECOS] CyaSSL library port (WIP): Space for struct corrupts other eCos-data in RAM X-SW-Source: 2013-09/txt/msg00018.txt.bz2 I'm working on a port of the CyaSSL SSL library by WolfSSL [1] to eCos-3.0 running on a Freescale MPC5668. The basic setup was quite simple and I was able to successfully run some of the tests. As soon as the tests started using structs though, I ran into weird problems which turned out to be caused by memory being overwritten as soon as the memory for the structs was set to 0 using the memset-function. The problem happens for example when I try to test the RSA-function which uses a variable "key" of type RsaKey: RsaKey key; "RsaKey" is a struct with the following definition: /* RSA */ typedef struct RsaKey { mp_int n, e, d, p, q, dP, dQ, u; int type; /* public or private */ void* heap; /* for user memory overrides */ #ifdef HAVE_CAVIUM /* Not set in my case, so I don't post content here */ #endif } RsaKey; The struct member "mp_int" is a typedef ... typedef fp_int mp_int; ... with "fp_int" being following struct: /* a FP type */ typedef struct { fp_digit dp[FP_SIZE]; int used, sign; } fp_int; "fp_digit" is a define: typedef unsigned int fp_digit; The system crashes after the function memset was called with the following parameters: s = 0x400031CC (the target address of "key") c = 0 n = 552 This call overwrites 552 bytes of memory starting from address 0x400031CC. This results in various variables needed by eCos in being 0ed and thus corrupting the system context, causing a reboot of my hardware shortly after. I created commented screenshots of the memory space before the memset-call [2] and after [3]. I've also made a posting about this issue on the CyaSSL forums [4], with no answers so far. Note that addresses posted there are slightly different as these were obtained by some previous debug-run. [1] http://wolfssl.com/yaSSL/Products-cyassl.html [2] http://oi41.tinypic.com/30bn4uv.jpg [3] http://oi39.tinypic.com/ou8bcm.jpg [4] http://www.yassl.com/forums/topic431-fastmath-memset-for-rsakey-corrupts-memory-on-ecosport-wip.html Can someone help in understanding the issue here as I'm not an C expert? It seems like at some point different data type sizes are assumed, which leads the compiler to put the struct in some place where not enough unused memory resides!? Thanks in advance! - Daniel -- View this message in context: http://sourceware-org.1504.n7.nabble.com/CyaSSL-library-port-WIP-Space-for-struct-corrupts-other-eCos-data-in-RAM-tp245720.html Sent from the Sourceware - ecos-discuss mailing list archive at Nabble.com. -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss